Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hychen/flutter_js_datascript
Using DataScript in Flutter Apps.
https://github.com/hychen/flutter_js_datascript
datascript flutter
Last synced: 27 days ago
JSON representation
Using DataScript in Flutter Apps.
- Host: GitHub
- URL: https://github.com/hychen/flutter_js_datascript
- Owner: hychen
- License: other
- Created: 2021-11-08T11:08:25.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-06T00:09:24.000Z (about 3 years ago)
- Last Synced: 2024-11-08T08:48:45.532Z (3 months ago)
- Topics: datascript, flutter
- Language: Dart
- Homepage:
- Size: 327 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Using DataScript in Flutter Apps.
> This package is in very early stage and only be tested on MacOS. Use it with caution and file
any potential issues you see.## Features
Use this package to
- Transact with Datoms.
- Query result by using [datalog](https://en.wikipedia.org/wiki/Datalog) language.### Supported APIs:
- creteConn
- q
- listen
- unlisten
- initDb
- datoms
- pull
- pullMany
- connFromDb
- connFromDatoms
- resetConn
- initDb
- dbWith
- emptyDb
- entityDb
- entity
- touch
- resolveTempids## Getting started
```shell
flutter pub add flutter_js_datascript
```## Usage
```dart
import 'package:flutter_js_datascript/flutter_js_datascript.dart';void main() async {
var d = Datascript();// create DB schema, a regular JS Object
final builder = SchemaBuilder()
..attr('aka', cardinality: Cardinality.many)
..attr('friend', valueType: ValueType.ref);
final schema = builder.build();// Use JS API to create connection and add data to DB
// create connection using schema
var conn = d.createConn(schema: schema);// setup listener called main
// pushes each entity (report) to an Array of reports
// This is just a simple example. Make your own!
var reports = [];
d.listen(conn, 'main', (report) {
reports.add(report);
});// define initial datoms to be used in transaction
var datoms = [
{
":db/id": -1,
"name": "Ivan",
"age": 18,
"aka": ["X", "Y"]
},
{
":db/id": -2,
"name": "Igor",
"aka": ["Grigory", "Egor"]
},
// use :db/add to link datom -2 as friend of datom -1
[":db/add", -1, "friend", -2]
];// Tx is Js Array of Object or Array
// pass datoms as transaction data
var report = d.transact(conn, datoms, txMeta: "initial info about Igor and Ivan");var db = d.db(conn);
// Fetch names of people who are friends with someone 18 years old
// query values from conn with JS API
var result = await d.q(
'[:find ?n :in \$ ?a :where [?e "friend" ?f] [?e "age" ?a] [?f "name" ?n]]',
[db, 18]);
// print query result to console!
print(result); // [["Igor"]]
}
```