diff --git a/bindings/dart/DEVELOPMENT.md b/bindings/dart/DEVELOPMENT.md new file mode 100644 index 000000000..2b25879cb --- /dev/null +++ b/bindings/dart/DEVELOPMENT.md @@ -0,0 +1,18 @@ +# Development + +## Pre-requisites + +- [Flutter](https://docs.flutter.dev/get-started/install) +- [Rust](https://www.rust-lang.org/tools/install) +- [frb](https://cjycode.com/flutter_rust_bridge/quickstart) + +## Steps + +- Modify rust code under `rust` directory; +- Inside this directory, run `flutter_rust_bridge_codegen generate` +- Modify dart code under `lib` directory; + +## Run test + +- From this directory, run `cargo build --package turso_dart --target-dir=rust/test_build` +- Run `flutter test` diff --git a/bindings/dart/README.md b/bindings/dart/README.md index f246558ce..9a3272e0a 100644 --- a/bindings/dart/README.md +++ b/bindings/dart/README.md @@ -2,14 +2,60 @@ Dart/Flutter binding for turso database. -## Pre-requisites +## Getting Started -- [Flutter](https://docs.flutter.dev/get-started/install) -- [Rust](https://www.rust-lang.org/tools/install) -- [frb](https://cjycode.com/flutter_rust_bridge/quickstart) +### Add it to your `pubspec.yaml`. -## Development +``` +turso_dart: +``` -- Modify rust code under `rust` directory; -- Inside this directory, run `flutter_rust_bridge_codegen generate` -- Modify dart code under `lib` directory; +### Create the client + +- In memory + +```dart +final client = TursoClient.memory(); +``` + +- Local + +```dart +final dir = await getApplicationCacheDirectory(); +final path = '${dir.path}/local.db'; +final client = TursoClient.local(path); +``` + +### Connect + +```dart +await client.connect(); +``` + +### Run SQL statements + +- Create table + +```dart +await client.execute("create table if not exists customers (id integer primary key, name text);"); +``` + +- Insert query + +```dart +await client.query("insert into customers(name) values ('John Doe')"); +``` + +- Select query + +```dart +print(await client.query("select * from customers")); +``` + +- Prepared statement + +```dart +final statement = await client + .prepare("select * from customers where id = ?"); +await statement.query(positional: [1]) +```