From c44268f9fab0dfd8371454e8b98773103201fae5 Mon Sep 17 00:00:00 2001 From: Andika Tanuwijaya Date: Wed, 2 Jul 2025 20:27:08 +0700 Subject: [PATCH] readme --- bindings/dart/DEVELOPMENT.md | 18 +++++++++++ bindings/dart/README.md | 62 +++++++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 bindings/dart/DEVELOPMENT.md 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]) +```