sql_lite_builder 1.0.0 copy "sql_lite_builder: ^1.0.0" to clipboard
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 on Database that returns a QueryBuilder.
  • Fluent method chaining: every builder method returns this.
  • All values are automatically bound as ? parameters β€” complete SQL Injection protection.

SELECT

  • select(columns) β€” choose specific columns
  • selectDistinct(columns) β€” add DISTINCT modifier
  • selectRaw(expression) β€” embed raw SQL expressions

WHERE β€” 12 variants

  • where(column, operator, value) β€” basic AND condition
  • orWhere(column, operator, value) β€” OR condition
  • whereIn(column, values) β€” IN (?, ...) clause
  • whereNotIn(column, values) β€” NOT IN (?, ...) clause
  • whereBetween(column, start, end) β€” BETWEEN ? AND ?
  • whereNotBetween(column, start, end) β€” NOT BETWEEN ? AND ?
  • whereNull(column) β€” IS NULL
  • whereNotNull(column) β€” IS NOT NULL
  • whereNested(callback) β€” nested AND group (...)
  • orWhereNested(callback) β€” nested OR group (...)
  • whereRaw(sql, bindings) β€” raw SQL fragment
  • orWhereRaw(sql, bindings) β€” raw SQL fragment with OR

JOIN

  • join(table, first, op, second) β€” INNER JOIN
  • leftJoin(table, first, op, second) β€” LEFT JOIN
  • crossJoin(table) β€” CROSS JOIN

ORDER BY

  • orderBy(column, {descending}) β€” ASC / DESC
  • orderByDesc(column) β€” shorthand for DESC
  • inRandomOrder() β€” ORDER BY RANDOM()

GROUP BY / HAVING

  • groupBy(column) β€” GROUP BY
  • having(expression, operator, value) β€” HAVING
  • havingRaw(expression) β€” raw HAVING expression

LIMIT / OFFSET / PAGINATION

  • limit(n) β€” LIMIT n
  • offset(n) β€” OFFSET n
  • paginate({page, perPage}) β€” automatic LIMIT + OFFSET from page number
  • forPage({page, perPage}) β€” alias for paginate

Terminal β€” READ

  • get() β€” all matching rows
  • getAs(mapper) β€” typed row list
  • first() β€” first row or null
  • firstAs(mapper) β€” typed first row or null
  • firstOrFail() β€” first row or RecordNotFoundException
  • firstOrFailAs(mapper) β€” typed first row or throws
  • value(column) β€” single column value
  • pluck(column) β€” flat list of one column
  • chunk(size, callback) β€” chunked processing

Terminal β€” AGGREGATES

  • count([column]) β€” COUNT
  • max(column) β€” MAX
  • min(column) β€” MIN
  • avg(column) β€” AVG
  • sum(column) β€” SUM
  • exists() β€” boolean existence check
  • doesntExist() β€” inverse of exists()

Terminal β€” WRITE

  • insert(data) β€” insert row, returns new id
  • insertOrIgnore(data) β€” INSERT OR IGNORE
  • upsert(data) β€” INSERT OR REPLACE
  • insertMany(rows) β€” batch insert via sqflite Batch
  • update(data) β€” update rows (requires WHERE)
  • updateAll(data) β€” update all rows (no WHERE required)
  • increment(column, {by, extra}) β€” atomic increment
  • decrement(column, {by, extra}) β€” atomic decrement
  • delete() β€” delete rows (requires WHERE)
  • truncate() β€” delete all rows

Safety Guards

  • DangerousOperationException thrown on update() / delete() without WHERE
  • InvalidOperatorException thrown on unsupported operator strings
  • UnsupportedDialectFeatureException thrown on SQLite-incompatible features (e.g. RIGHT JOIN)

Debug

  • toSql() β€” inspect generated SQL
  • toSqlWithBindings() β€” inspect SQL + bindings

Transactions

  • db.transactionSafe(callback) β€” extension method returning QueryTransaction
  • QueryTransaction.table(name) β€” full builder API within transaction

Schema System (optional)

  • TableSchema β€” abstract class for declarative table definitions
  • ColumnDefinition β€” typed column builder with all SQLite constraints
  • IndexDefinition β€” typed index declarations
  • TableSchema.toCreateSql() β€” generates CREATE TABLE IF NOT EXISTS ...
  • TableSchema.toDropSql() β€” generates DROP TABLE IF EXISTS ...
  • TableSchema.allCreateStatements() β€” table + all indexes

Column Types

  • ColumnDefinition.integer(name) β€” INTEGER
  • ColumnDefinition.text(name) β€” TEXT
  • ColumnDefinition.real(name) β€” REAL
  • ColumnDefinition.blob(name) β€” BLOB
  • ColumnDefinition.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 _migrations meta-table
  • db.migrations.runAll(list) β€” run all pending migrations
  • db.migrations.isApplied(version) β€” check status
  • db.migrations.rollbackLast() β€” remove last applied version
  • db.migrations.appliedVersions() β€” full set of applied versions
  • Migration(version, up, {down, description}) β€” migration definition

Typed Result Extensions

  • QueryResultExtension.getAs(mapper) β€” typed list
  • QueryResultExtension.firstAs(mapper) β€” typed first
  • QueryResultExtension.firstOrFailAs(mapper) β€” typed first or throws
  • QueryResultExtension.getIndexedBy(keyColumn, mapper) β€” lookup map
  • QueryResultExtension.groupedBy(keyColumn, mapper) β€” grouped map
  • QueryResultExtension.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 β†’ bool
  • TypeConverter.toDateTime(value) β€” ISO TEXT β†’ DateTime
  • TypeConverter.toEnum(value, values) β€” TEXT β†’ Enum
  • TypeConverter.toInt, toDouble, toText helpers

Configuration & Logging

  • SqlLiteBuilderConfig.configure(...) β€” global config
  • SqlLiteLogger β€” debug-mode-only logger (stripped in release)

Database Extension Helpers

  • db.tableExists(name) β€” check table existence
  • db.columnExists(table, column) β€” check column existence
  • db.rowCount(table) β€” quick count
  • db.setForeignKeys(enabled) β€” toggle FK enforcement
  • db.vacuum() β€” optimize database file
  • db.getUserVersion(), db.setUserVersion(v) β€” user_version pragma

0.1.0 β€” 2025-12-01 #

  • Pre-release development snapshot
  • Core builder, WHERE, compiler, and parameter binder
0
likes
140
points
9
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

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.

Repository (GitHub)
View/report issues

Topics

#sqlite #database #query-builder #sqflite #type-safe

License

MIT (license)

Dependencies

flutter, meta, path, sqflite

More

Packages that depend on sql_lite_builder