dart_db 0.3.6
dart_db: ^0.3.6 copied to clipboard
Embedded database for Dart servers: tables from your own models, Diesel-style queries, joins and transactions (db_dsl) on Rust and LMDB 1.0, for Linux, macOS and Windows.
dart_db example #
server.dart is a small HTTP API on dart_db:
GET /notes?author=adalists the notes of an author, through an index;POST /noteswith{"id": 1, "author": "ada", "text": "..."}stores one, and a duplicate id answers409from theConstraintErrorof the insert.
The Note model is a plain class with fromJson and toJson that carries
its table:
static final DbTable<Note> table = DbTable<Note>(
'notes',
key: 'id',
fromJson: Note.fromJson,
indexes: [Index(['author'])],
);
DartDb.open(path) lists no table: notes defines itself on its first use.
The routes query Note.table.author.eq(name) through NoteFields, the
extension the db_dsl_lints analyzer
plugin writes from the model.
Run it, or compile it ahead of time with the native library bundled:
dart run example/server.dart
dart build cli -t example/server.dart -o build/server
./build/server/bundle/bin/server