surrealdb_js 1.0.1+7 copy "surrealdb_js: ^1.0.1+7" to clipboard
surrealdb_js: ^1.0.1+7 copied to clipboard

Platformweb

Flutter SurrealDB SDK for JavaScript

surrealdb_js #

pub package browser tests style: very good analysis Powered by Mason License: MIT

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

Alternatively, add surrealdb_js to your pubspec.yaml:

dependencies:
  surrealdb_js:

Install it:

flutter pub get

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>

✨ 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);

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 name ON test TYPE string;');
    txn.query(
      r'CREATE test SET name = $name;',
      bindings: {'name': 'John'},
    );
    if (somethingWrong) {
      txn.cancel();
    }
  },
);

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}},
}
0
likes
150
pub points
18%
popularity

Publisher

unverified uploader

Flutter SurrealDB SDK for JavaScript

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

MIT (license)

Dependencies

flutter, json_annotation, logger

More

Packages that depend on surrealdb_js