knex_dart_sqlite 0.4.0 copy "knex_dart_sqlite: ^0.4.0" to clipboard
knex_dart_sqlite: ^0.4.0 copied to clipboard

SQLite driver for knex_dart — connect and execute queries against a SQLite database using the knex_dart query builder.

knex_dart_sqlite #

SQLite driver for knex_dart — execute queries against a SQLite database using the knex_dart query builder.

Pub Version License: MIT

Installation #

dependencies:
  knex_dart_sqlite: ^0.4.0

Usage #

import 'package:knex_dart_sqlite/knex_dart_sqlite.dart';

// Pick one connection style for your app:
final db = await KnexSQLite.connect(filename: 'app.db');
// final db = await KnexSQLite.connect(filename: ':memory:');
// final db = await KnexSQLite.connect(
//   filename: 'app.db',
//   webStorageMode: 'auto', // auto | opfs | indexedDb | memory
// );

// Schema
await db.executeSchema(
  (schema) {
    schema.createTable('users', (t) {
      t.increments('id');
      t.string('name').notNullable();
      t.string('email').unique();
      t.timestamps();
    });
  },
);

// INSERT
await db.insert(
  db('users').insert({'name': 'Alice', 'email': 'alice@example.com'}),
);

// SELECT
final users = await db.select(
  db('users').where('active', '=', true).orderBy('name'),
);

// UPDATE
await db.update(
  db('users').where('id', '=', 1).update({'name': 'Bob'}),
);

// DELETE
await db.delete(
  db('users').where('id', '=', 1).delete(),
);

// Transactions
await db.trx((trx) async {
  await trx.insert(trx('accounts').insert({'balance': 100}));
  await trx.update(trx('accounts').where('id', '=', 1).update({'balance': 0}));
});

// Reactive query watching
final sub = db.watch(
  db('users').where('active', '=', true).orderBy('name'),
  debounce: const Duration(milliseconds: 100),
).listen((rows) {
  print('Active users changed: ${rows.length}');
});

await sub.cancel();
await db.close();

SQLite-specific features #

  • ? positional placeholders
  • Double-quoted identifier quoting
  • In-memory database support (:memory:)
  • Browser/WASM storage modes: memory, indexedDb, opfs, auto
  • JSON operators via json_extract()
  • Nested transactions via savepoints
  • Top-level transaction serialization on SQLite's single connection
  • Reactive watch() query streams

webStorageMode is only supported on web/WASM. On native SQLite, passing it to connect() throws UnsupportedError.

Documentation #

See also #

1
likes
140
points
88
downloads

Documentation

API reference

Publisher

verified publishermahawarkartikey.in

Weekly Downloads

SQLite driver for knex_dart — connect and execute queries against a SQLite database using the knex_dart query builder.

Repository (GitHub)
View/report issues
Contributing

Topics

#sql #query-builder #database #sqlite #knex

License

MIT (license)

Dependencies

knex_dart, logging, sqlite3, sqlite3_web, universal_io

More

Packages that depend on knex_dart_sqlite