surrealdb_wasm 1.0.1+15 copy "surrealdb_wasm: ^1.0.1+15" to clipboard
surrealdb_wasm: ^1.0.1+15 copied to clipboard

Platformweb

Flutter SurrealDB WebAssembly(WASM) package

surrealdb_wasm #

pub package browser tests style: very good analysis License: MIT

The Flutter SurrealDB WebAssembly (WASM) package is a powerful integration for Flutter, built upon the foundation of surrealdb.wasm, the WebAssembly engine for the SurrealDB JavaScript SDK. Consequently, the surrealdb_js package will provide an unified API for the WebAssembly engine.

🔍 Demo #

Try out surreal_wasm applications in your browser:

💻 Installation #

❗ In order to start using surrealdb_wasm you must have the Flutter SDK installed on your machine.

Install via flutter pub add:

flutter pub add surrealdb_wasm

Alternatively, add surrealdb_wasm to your pubspec.yaml:

dependencies:
  surrealdb_wasm:

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.bundled.mjs";
  import { surrealdbWasmEngines } from "/assets/packages/surrealdb_wasm/assets/wasm/surrealdb/index.bundled.js";
  
  // expose the type to the global scope
  globalThis.SurrealJS = Surreal;
  globalThis.StringRecordId = StringRecordId;
  globalThis.WasmEngine = surrealdbWasmEngines;
</script>

✨ Features #

Please refer to the surrealdb_js package for a comprehensive list of features.

🏃 Examples #

Basic #

import 'package:surrealdb_js/surrealdb_js.dart';
import 'package:surrealdb_wasm/surrealdb_wasm.dart';

final db = SurrealWasm.getInstance();

await db.connect('indxdb://surreal');
await db.use(namespace: 'test', database: 'test');

final created = db.create('person',
          {
            'title': 'CTO',
            'name': {
              'first': 'Tom',
              'last': 'Jerry',
            },
            'marketing': true,
          },
        );

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((txn) async {
    txn.query('DEFINE TABLE test SCHEMAFULL;');
    txn.query(r'DEFINE FIELD id ON test VALUE <record>($value) ASSERT $value != NONE;');
    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 or 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_wasm,
  author = {Lim Chee Kin},
  title = {surrealdb_wasm: Flutter SurrealDB WebAssembly(WASM) package},
  year = {2023},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/limcheekin/surrealdb_wasm}},
}
3
likes
150
pub points
43%
popularity

Publisher

unverified uploader

Flutter SurrealDB WebAssembly(WASM) package

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

MIT (license)

Dependencies

flutter, surrealdb_js

More

Packages that depend on surrealdb_wasm