raindrop_sqlite 0.1.1
raindrop_sqlite: ^0.1.1 copied to clipboard
The SQLite driver for raindrop, built on top of the sqlite3 package.
💧 raindrop_sqlite
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"
insertOrIgnorerendersINSERT 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 forSQLITE_ENABLE_UPDATE_DELETE_LIMITand falls back to a key-based rewrite.unixepoch()andcurrentTimestamp()evaluate in the database.- Column types beyond the core set:
boolean,dateTime(milliseconds since the epoch),bigIntandblob.