0 purchases
surrealdb js
surrealdb_js #
The Flutter SurrealDB SDK for JavaScript package is a powerful integration for Flutter, built upon the foundation of surrealdb.js, the official SurrealDB SDK for JavaScript.
Installation 💻 #
❗ In order to start using surrealdb_js you must have the Flutter SDK installed on your machine.
Install via flutter pub add:
flutter pub add surrealdb_js
copied to clipboard
Alternatively, add surrealdb_js to your pubspec.yaml:
dependencies:
surrealdb_js:
copied to clipboard
Install it:
flutter pub get
copied to clipboard
Lastly, add the following code before the </head> tag in the web/index.html file:
<script type="module">
import { Surreal, StringRecordId } from "/assets/packages/surrealdb_js/assets/js/index.js";
// expose the type to the global scope
globalThis.SurrealJS = Surreal;
globalThis.StringRecordId = StringRecordId;
</script>
copied to clipboard
✨ Features #
[x] connect()
[x] close()
[x] use()
[x] create()
[x] update()
[x] merge()
[x] delete()
[x] select()
[x] query()
[x] query_raw()
[x] transaction()
[x] let()
[x] unset()
[x] signup()
[x] signin()
[x] invalidate()
[x] authenticate()
[x] info()
[x] patch()
[x] version()
🏃 Examples #
Basic #
final db = Surreal();
await db.connect('http://127.0.0.1:8000/rpc');
await db.use(namespace: 'surreal', database: 'surreal');
await db.signin({'username': 'root', 'password': 'root'});
final created = db.create('person',
{
'title': 'CTO',
'name': {
'first': 'Tom',
'last': 'Jerry',
},
'marketing': true,
},
);
// created['id'] = person:b9eht8bie8abf0vbcfxh
final id = created['id'].toString();
final merged = await db.merge(
id,
{
'marketing': false,
},
);
final tom = await db.select(id);
final deleted = await db.delete(id);
copied to clipboard
For more code examples, kindly refer to the integration test and the example project.
Transaction Support #
final result = await db.transaction(
showSql: true,
(txn) async {
txn.query('DEFINE TABLE test SCHEMAFULL;');
txn.query('DEFINE FIELD id ON test TYPE record;');
txn.query('DEFINE FIELD name ON test TYPE string;');
txn.query(
r'CREATE test SET name = $name;',
bindings: {'name': 'John'},
);
if (somethingWrong) {
txn.cancel();
}
},
);
copied to clipboard
For more code examples, kindly refer to the integration test of transaction.
🧑💼 Contributing #
Contributions are welcome! Please check out the unimplemented features above, issues on the repository, and feel free to open a pull request.
For more information, please see the contribution guide.
📔 License #
This project is licensed under the terms of the MIT license.
🗒️ Citation #
If you utilize this package, please consider citing it with:
@misc{surrealdb_js,
author = {Lim Chee Kin},
title = {surrealdb_js: Flutter SurrealDB SDK for JavaScript package},
year = {2024},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/limcheekin/surrealdb_js}},
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.