sqflite-crud-and-transactions

Implements CRUD operations, transactions, and batches with the sqflite Flutter plugin.

3.0k|555|Updated May 22, 2017
One-click install
npx skills add https://github.com/tekartik/sqflite --skill sqflite-crud-and-transactions-tekartik
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sqflite-crud-and-transactions
Source: https://github.com/tekartik/sqflite/tree/main/sqflite/skills/sqflite-crud-and-transactions
Command: npx skills add https://github.com/tekartik/sqflite --skill sqflite-crud-and-transactions-tekartik

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing correct SQLite data access code in Flutter with package:sqflite requires knowing many subtle rules: binding arguments instead of interpolating strings, avoiding deadlocks by using only the transaction object inside transaction callbacks, handling unsupported Dart types like bool and DateTime, and streaming large result sets without exhausting memory. This Skill encodes those rules so generated database code works correctly the first time. ## Core Features & Use Cases - CRUD and raw SQL guidance: Covers insert, query, update, delete and their raw variants, where/whereArgs binding, IN-clause placeholder generation, ConflictAlgorithm upserts, and reserved-name escaping with escapeName. - Transactions and batches: Explains BEGIN IMMEDIATE semantics, rollback on throw, the db-vs-txn deadlock pitfall, batch commit/apply behavior, and noResult/continueOnError options. - Large results and error handling: Details queryCursor/queryIterate streaming, the 1 MB Android CursorWindow limit, SqfliteSqlCommand reuse, and DatabaseException helpers like isUniqueConstraintError and isNoSuchTableError. - Use Case: Build a Todo DAO in Flutter that inserts rows, queries with bound WHERE clauses, performs an atomic balance transfer in a transaction, and imports a product list in a single batch. ## Quick Start Use the sqflite-crud-and-transactions skill to write a Dart DAO class that inserts, queries, updates, and deletes rows in a Todo table with proper argument binding and a transaction for multi-step writes.

Frequently Asked Questions about sqflite-crud-and-transactions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I insert and query rows with sqflite in Flutter?▼

Use db.insert('Todo', {'title': title}) which returns the new row id, and db.query('Todo', where: 'done = ?', whereArgs: [0]) which returns a List<Map<String, Object?>>. Always bind values with ? placeholders instead of interpolating strings into SQL.

How do I use transactions in sqflite without deadlocking?▼

Call db.transaction((txn) async {...}) and use only the txn object inside the callback. Calling db inside the callback waits for the transaction and deadlocks, printing a 'database has been locked' warning after 10 seconds. Throw inside the callback to roll back.

How do I perform an upsert with sqflite?▼

Pass conflictAlgorithm: ConflictAlgorithm.replace to db.insert to delete conflicting rows and insert the new one, or use ConflictAlgorithm.ignore to skip conflicts. Alternatively catch DatabaseException and check isUniqueConstraintError() to run an update instead.

Can sqflite store bool or DateTime values directly?▼

No, sqflite only supports int, num, String, Uint8List, and null as column values. Store bool as INTEGER 0/1 and DateTime as millisecondsSinceEpoch or an ISO 8601 string; passing other types prints a debug warning and will throw in the future.

Why does an IN clause with a list argument fail in sqflite?▼

sqflite does not expand a list argument for IN (?). Generate one ? per value, for example 'id IN (${List.filled(ids.length, '?').join(',')})', and pass the list as whereArgs so each value binds to its own placeholder.

How do I query large tables in sqflite without loading all rows into memory?▼

Use queryCursor or rawQueryCursor with a bufferSize and iterate with moveNext, closing the cursor in a finally block, or use the queryIterate extension whose onRow callback returns false to stop early. Rows over roughly 1 MB fail on Android due to CursorWindow limits.