sqlitenow_runtime 0.15.0 copy "sqlitenow_runtime: ^0.15.0" to clipboard
sqlitenow_runtime: ^0.15.0 copied to clipboard

Dart runtime contracts for SQLiteNow generated code.

sqlitenow_runtime #

The Dart runtime for type-safe SQLite databases generated by SQLiteNow.

Define your schema and queries in SQL, run the SQLiteNow generator, and use the generated database, parameter, and result types from your Dart or Flutter application. sqlitenow_runtime provides the SQLite lifecycle, migrations, transactions, query execution, and reactive invalidation used by that generated code.

This package targets Dart VM and Flutter native applications.

Install #

Use the same version for the SQLiteNow runtime and generator:

dependencies:
  sqlitenow_runtime: ^0.10.0

dev_dependencies:
  sqlitenow_cli: ^0.10.0

Define your database #

Create SQL files for your schema and queries. For example:

-- lib/db/sql/AppDatabase/schema/task.sql
CREATE TABLE task (
  id INTEGER PRIMARY KEY NOT NULL,
  title TEXT NOT NULL,
  completed INTEGER NOT NULL
);
-- lib/db/sql/AppDatabase/queries/task/insertOne.sql
INSERT INTO task (id, title, completed)
VALUES (:id, :title, :completed);
-- lib/db/sql/AppDatabase/queries/task/selectAll.sql
SELECT id, title, completed
FROM task
ORDER BY id;

Configure the generator in sqlitenow.yaml:

databases:
  AppDatabase:
    input: lib/db/sql/AppDatabase
    output: lib/db/generated
    package: app.db
    runtime: dart
    oversqlite: false

Generate the Dart API:

dart run sqlitenow_cli generate

For a Flutter application, use:

flutter pub run sqlitenow_cli generate

Use the generated API #

SQLiteNow generates the database class, typed query parameters, and result rows:

import 'db/generated/app_database.dart';

Future<void> useDatabase(String databasePath) async {
  final database = AppDatabase(path: databasePath);
  await database.open();

  try {
    await database.task.insertOne(
      const TaskInsertOneParams(
        id: 1,
        title: 'Try SQLiteNow',
        completed: 0,
      ),
    );

    final tasks = await database.task.selectAll().asList();
    for (final task in tasks) {
      print('${task.id}: ${task.title}');
    }
  } finally {
    await database.close();
  }
}

Query folders become namespaces such as database.task. Named SQL parameters become generated parameter classes, and SELECT columns become typed result objects.

Generated SELECT queries support one-shot and reactive reads:

final tasks = await database.task.selectAll().asList();
final taskStream = database.task.selectAll().watch();

Generated writes automatically notify matching query streams. Use the generated database's transaction(...) method when several operations must commit together.

Most application code should use these generated APIs rather than constructing low-level runtime types directly.

Learn more #

0
likes
130
points
181
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Dart runtime contracts for SQLiteNow generated code.

Repository (GitHub)
View/report issues

License

Apache-2.0 (license)

Dependencies

sqlite3

More

Packages that depend on sqlitenow_runtime