dartonic_sqlite 1.0.0 copy "dartonic_sqlite: ^1.0.0" to clipboard
dartonic_sqlite: ^1.0.0 copied to clipboard

SQLite driver for Dartonic. Provides connectSqlite() to create a type-safe database connection.

dartonic_sqlite #

SQLite driver for Dartonic. Uses the sqlite3 package.

Installation #

dependencies:
  dartonic_sqlite:
    path: ../dartonic_sqlite

Connection #

import 'package:dartonic_sqlite/dartonic_sqlite.dart';

final db = await connectSqlite(
  'app.db',            // file path, or ':memory:' for in-memory
  schemas: [users, posts],
);
Parameter Type Default Description
path String required File path or :memory:
schemas List<TableSchema> required Tables to register
views List<ViewSchema> [] Views to create
relations List<RelationsTable> [] Relation join tables
sync bool true Run CREATE TABLE IF NOT EXISTS on connect

Schema Definition #

Use sqliteTable — validates that column types are SQLite-compatible (INTEGER, TEXT, REAL, BLOB, DATETIME).

import 'package:dartonic_core/dartonic_core.dart';

final users = sqliteTable('users', {
  'id': integer().primaryKey(autoIncrement: true),
  'name': text().notNull(),
  'email': text().notNull().unique(),
  'created_at': datetime().defaultNow(),
});

final posts = sqliteTable('posts', {
  'id': integer().primaryKey(autoIncrement: true),
  'user_id': integer().references(() => 'users.id'),
  'title': text().notNull(),
  'body': text(),
});

Usage #

// SELECT
final rows = await db.select().from(users);

// Typed SELECT
final rows = await db.select({
  'id':    users.id,
  'email': users.email,
}).from(users);

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

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

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

// JOIN
await db
    .select()
    .from(posts)
    .innerJoin(users, eq(posts.user_id, users.id));

// Raw query
final rows = await db.rawQuery('SELECT * FROM users WHERE id = ?', [1]);

Migrations #

await db.migrate(migrationsDir: 'db/migrations');

In-memory database #

final db = await connectSqlite(':memory:', schemas: [users]);

Notes #

  • Foreign keys are enabled automatically (PRAGMA foreign_keys = ON)
  • RETURNING requires SQLite 3.35+
  • INTEGER PRIMARY KEY AUTOINCREMENT mapped from .primaryKey(autoIncrement: true)
0
likes
130
points
40
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

SQLite driver for Dartonic. Provides connectSqlite() to create a type-safe database connection.

Repository (GitHub)
View/report issues

Topics

#orm #database #sqlite

License

MIT (license)

Dependencies

dartonic_core, sqlite3

More

Packages that depend on dartonic_sqlite