sql_lite_builder 1.0.0
sql_lite_builder: ^1.0.0 copied to clipboard
A type-safe, fluent SQL query builder for Flutter and sqflite that enables clean, composable queries without raw SQL strings, offering automatic parameterization and built-in SQL injection protection.
Changelog #
All notable changes to sql_lite_builder are documented here.
This project adheres to Semantic Versioning.
1.0.0 β 2026-05-30 #
π Initial Release #
Core Builder API
db.table(name)β Extension method onDatabasethat returns aQueryBuilder.- Fluent method chaining: every builder method returns
this. - All values are automatically bound as
?parameters β complete SQL Injection protection.
SELECT
select(columns)β choose specific columnsselectDistinct(columns)β addDISTINCTmodifierselectRaw(expression)β embed raw SQL expressions
WHERE β 12 variants
where(column, operator, value)β basic AND conditionorWhere(column, operator, value)β OR conditionwhereIn(column, values)βIN (?, ...)clausewhereNotIn(column, values)βNOT IN (?, ...)clausewhereBetween(column, start, end)βBETWEEN ? AND ?whereNotBetween(column, start, end)βNOT BETWEEN ? AND ?whereNull(column)βIS NULLwhereNotNull(column)βIS NOT NULLwhereNested(callback)β nested AND group(...)orWhereNested(callback)β nested OR group(...)whereRaw(sql, bindings)β raw SQL fragmentorWhereRaw(sql, bindings)β raw SQL fragment with OR
JOIN
join(table, first, op, second)βINNER JOINleftJoin(table, first, op, second)βLEFT JOINcrossJoin(table)βCROSS JOIN
ORDER BY
orderBy(column, {descending})βASC/DESCorderByDesc(column)β shorthand for DESCinRandomOrder()βORDER BY RANDOM()
GROUP BY / HAVING
groupBy(column)βGROUP BYhaving(expression, operator, value)βHAVINGhavingRaw(expression)β rawHAVINGexpression
LIMIT / OFFSET / PAGINATION
limit(n)βLIMIT noffset(n)βOFFSET npaginate({page, perPage})β automatic LIMIT + OFFSET from page numberforPage({page, perPage})β alias forpaginate
Terminal β READ
get()β all matching rowsgetAs(mapper)β typed row listfirst()β first row or nullfirstAs(mapper)β typed first row or nullfirstOrFail()β first row orRecordNotFoundExceptionfirstOrFailAs(mapper)β typed first row or throwsvalue(column)β single column valuepluck(column)β flat list of one columnchunk(size, callback)β chunked processing
Terminal β AGGREGATES
count([column])βCOUNTmax(column)βMAXmin(column)βMINavg(column)βAVGsum(column)βSUMexists()β boolean existence checkdoesntExist()β inverse ofexists()
Terminal β WRITE
insert(data)β insert row, returns new idinsertOrIgnore(data)βINSERT OR IGNOREupsert(data)βINSERT OR REPLACEinsertMany(rows)β batch insert via sqfliteBatchupdate(data)β update rows (requires WHERE)updateAll(data)β update all rows (no WHERE required)increment(column, {by, extra})β atomic incrementdecrement(column, {by, extra})β atomic decrementdelete()β delete rows (requires WHERE)truncate()β delete all rows
Safety Guards
DangerousOperationExceptionthrown onupdate()/delete()without WHEREInvalidOperatorExceptionthrown on unsupported operator stringsUnsupportedDialectFeatureExceptionthrown on SQLite-incompatible features (e.g. RIGHT JOIN)
Debug
toSql()β inspect generated SQLtoSqlWithBindings()β inspect SQL + bindings
Transactions
db.transactionSafe(callback)β extension method returningQueryTransactionQueryTransaction.table(name)β full builder API within transaction
Schema System (optional)
TableSchemaβ abstract class for declarative table definitionsColumnDefinitionβ typed column builder with all SQLite constraintsIndexDefinitionβ typed index declarationsTableSchema.toCreateSql()β generatesCREATE TABLE IF NOT EXISTS ...TableSchema.toDropSql()β generatesDROP TABLE IF EXISTS ...TableSchema.allCreateStatements()β table + all indexes
Column Types
ColumnDefinition.integer(name)βINTEGERColumnDefinition.text(name)βTEXTColumnDefinition.real(name)βREALColumnDefinition.blob(name)βBLOBColumnDefinition.boolean(name)βINTEGER(0/1)ColumnDefinition.dateTime(name)βTEXT(ISO 8601)ColumnDefinition.json(name)βTEXT(JSON string)ColumnDefinition.numeric(name)βNUMERIC
Column Modifiers
.primaryKey(),.autoIncrement(),.notNull(),.nullable(),.unique().withDefault(value),.defaultValue(value),.defaultNow(),.defaultExpression(expr).references(table, column, {onDelete, onUpdate})β foreign key.check(expression)β CHECK constraint
Migration System
MigrationRunnerβ tracks applied versions in_migrationsmeta-tabledb.migrations.runAll(list)β run all pending migrationsdb.migrations.isApplied(version)β check statusdb.migrations.rollbackLast()β remove last applied versiondb.migrations.appliedVersions()β full set of applied versionsMigration(version, up, {down, description})β migration definition
Typed Result Extensions
QueryResultExtension.getAs(mapper)β typed listQueryResultExtension.firstAs(mapper)β typed firstQueryResultExtension.firstOrFailAs(mapper)β typed first or throwsQueryResultExtension.getIndexedBy(keyColumn, mapper)β lookup mapQueryResultExtension.groupedBy(keyColumn, mapper)β grouped mapQueryResultExtension.paginateAs(page, perPage, mapper)βPaginatedResult<T>PaginatedResultβ data + total + lastPage + hasNextPage + hasPrevPage
Type Conversion
TypeConverter.toSqlite(value)β Dart β SQLite (bool, DateTime, Enum)TypeConverter.toBool(value)β SQLite INTEGER β boolTypeConverter.toDateTime(value)β ISO TEXT β DateTimeTypeConverter.toEnum(value, values)β TEXT β EnumTypeConverter.toInt,toDouble,toTexthelpers
Configuration & Logging
SqlLiteBuilderConfig.configure(...)β global configSqlLiteLoggerβ debug-mode-only logger (stripped in release)
Database Extension Helpers
db.tableExists(name)β check table existencedb.columnExists(table, column)β check column existencedb.rowCount(table)β quick countdb.setForeignKeys(enabled)β toggle FK enforcementdb.vacuum()β optimize database filedb.getUserVersion(),db.setUserVersion(v)β user_version pragma
0.1.0 β 2025-12-01 #
- Pre-release development snapshot
- Core builder, WHERE, compiler, and parameter binder