💧 raindrop_sqlite

Pub ci coverage style: very good analysis License: MIT


The SQLite driver for raindrop, built on sqlite3.

Usage

Declare tables with sqliteTable, then hand a SQLiteDelegate to Raindrop:

import 'package:raindrop/raindrop.dart';
import 'package:raindrop_sqlite/raindrop_sqlite.dart';
import 'package:sqlite3/sqlite3.dart';

final users = sqliteTable('users', UserSchema.new);

void main() async {
  final db = Raindrop(SQLiteDelegate(sqlite3.openInMemory()));

  final [user] = await db.insert(into: users).values([
    const User(name: 'Alex'),
  ]).returning();
}

SQLite ships with foreign key enforcement off, so the delegate turns it on for its connection. Pass enforceForeignKeys: false to keep your own setting.

Beyond the core DSL

Everything in the core raindrop DSL works unchanged. On top of it this driver adds upserts:

await db.insert(into: users).values([user])
    .onConflict([users.email])
    .doUpdate([users.age.to(excluded(users.age))]);
// INSERT ... ON CONFLICT ("email") DO UPDATE SET "age" = "excluded"."age"
  • insertOrIgnore renders INSERT OR IGNORE, skipping conflicting rows.
  • returning() on inserts, updates and deletes yields the affected rows.
  • .limit(n) caps updates and deletes. The driver probes the library for SQLITE_ENABLE_UPDATE_DELETE_LIMIT and falls back to a key-based rewrite.
  • unixepoch() and currentTimestamp() evaluate in the database.
  • Column types beyond the core set: boolean, dateTime (milliseconds since the epoch), bigInt and blob.

Libraries

ddl
raindrop_sqlite