sql_engine 2.0.6
sql_engine: ^2.0.6 copied to clipboard
A thin yet powerful SQLite layer for Dart & Flutter.
2.0.5 – 2025-07-05 #
Added #
-
Binary Serialization Helpers (
toBytes/fromBytes)
Every generated model now includes a zero‑allocation binary codec:final bytes = user.toBytes(); // → Uint8List final user2 = UserBinary.fromBytes(bytes);- Column order follows the latest
@SqlSchema. - Little‑endian layout with compact variable‑length encoding for
StringandBLOB. - Nullable columns use a one‑byte presence flag (0 / 1).
- Fully type‑safe –
DateTimestored asint64milliseconds,boolas0/1. - Thorough test‑suite (
test/binary_codec_test.dart) covers:- Round‑trip of all field types
- Nullable vs non‑nullable columns
- Edge‑cases: empty strings/blobs, max/min numeric values, very long payloads.
Example
final order = Order( id: 9, customerId: 42, orderDate: DateTime.utc(2025, 7, 1, 18), total: 123.45, ); final data = order.toBytes(); // serialize final copy = OrderBinary.fromBytes(data); assert(copy.total == 123.45); // - Column order follows the latest
2.0.4 – 2025-06-29 #
Added #
-
Soft Delete Support
- You can now enable soft deletion using
@SqlTable(softDelete: true).@SqlTable(tableName: 'users', version: 1, softDelete: true) class User { ... } - When enabled:
- All
deleteById()operations updatedeleted_at = CURRENT_TIMESTAMPinstead of removing rows. - All
findAll()andfindWhere()queries automatically exclude soft-deleted rows by default. - Use
includeDeleted: trueto include them. - A new helper
restoreById()is generated to restore soft-deleted rows.
- All
- Supports:
- Nullable
deleted_atcolumn (added automatically if missing) - Standard SQLite timestamp
- Reversible deletes via
restoreById()
- Nullable
Example
await UserCrudHelpers.deleteById(db, 5); // sets deleted_at await UserCrudHelpers.findAll(db); // excludes deleted await UserCrudHelpers.findAll(db, includeDeleted: true); // includes deleted await UserCrudHelpers.restoreById(db, 5); // restores recordFully tested under
test/soft_delete_test.dart— including restore and manual inspection via raw SQL. - You can now enable soft deletion using
2.0.3 - 2025-06-12 #
Added #
- Initial Seed Data Support
@SqlSchemanow accepts aseedDatafield:@SqlSchema( version: 1, columns: [...], seedData: [ {'name': 'Alice', 'male': false}, {'name': 'Bob', 'male': true}, ], )- Seed rows are automatically inserted into the table on first creation only.
- Supports:
DateTime(usemillisecondsSinceEpoch)bool(stored as0/1)nullvalues
- Automatically skipped if the table already exists.
- Available during
db.open()lifecycle — no extra config required.
Example #
@SqlSchema(
version: 1,
columns: [...],
seedData: [
{
'name': 'Ada',
'male': true,
'created_at': DateTime(2024, 1, 1).millisecondsSinceEpoch,
}
],
)
2.0.2 - 2025-06-10 #
- updated documentation for models
2.0.1 - 2025-06-08 #
✨ Added #
-
Strongly-Typed CRUD Code Generation
New generator methods now create full CRUD extensions for each model/table:insert<Entity>()update<Entity>()upsert<Entity>()delete<Entity>ById()delete<Entity>Where()flush<Entity>s()findAll<Entity>s()find<Entity>sWhere()
These methods are emitted as
extension <Entity>Crud on SqlEngineDatabase, with support for:- Named parameter helpers (
<Entity>CrudHelpers) - Automatic conversion of
DateTime→millisecondsSinceEpoch - Nullable field safety
- Strongly-typed model mapping with
<Entity>Mapper.fromRow
Example
await User.insert( db, id: 1, name: 'Jane Smith', male: true, createdAt: DateTime.now(), ); final users = await User.findWhere(db, 'name = ?', 'Jane Smith');
2.0.0 - 2025-06-01 #
⚠️ Breaking Changes #
-
SqlColumn.typeis now required to be aSqlTypeenum instead of a string. This improves type safety and autocompletion.- Before:
SqlColumn(name: 'id', type: 'INTEGER') - After:
SqlColumn(name: 'id', type: SqlType.integer)
- Before:
-
Code generators have been updated to map
SqlTypeto proper SQL keywords inCREATE TABLE,ALTER TABLE, and index creation.
1.0.6 - 2025-05-04 #
Added #
enableLogparameter toSqlEngineDatabaseconstructor. This allows consumers of the package to disable or control logging, instead of relying on a global compile-time flag.final db = SqlEngineDatabase(enableLog: false);
[1.0.5] – 2025‑05‑03 #
Fixed #
- Mapper code‑gen
- Removed illegal trailing
?intoRow()for nullable fields (e.g. now emits
'locationLat': locationLat,instead of'locationLat': locationLat?,). - Null‑safe write for
DateTime(createdAt?.millisecondsSinceEpoch) and forbool(male == true ? 1 : null).
- Removed illegal trailing
Added #
@SqlIndexannotation- Define one or more indexes per table.
@SqlIndex(name: 'idx_user_email', columns: ['email']) - Generator now outputs a
createIndexeslist inside each*Tableclass. _onCreate()automatically executes allCREATE INDEXstatements after tables are created.
- Define one or more indexes per table.
Migration #
No breaking API changes. Re‑run build_runner to regenerate code and
indexes will be created automatically the next time the database is
initialized.
1.0.4 - 2025-05-03 #
Added #
- Introduced
@SqlIndexannotation for defining named indexes on tables. - Generator now reads and embeds indexes as part of the generated table class.
- Database applies all defined indexes automatically during
open()on initial creation. - Added
createIndexesoverride inSqlEngineTableto allow per-table index registration. - Added test support:
- Verify index creation using
PRAGMA index_list. - Verify index usage via
EXPLAIN QUERY PLAN.
- Verify index creation using
Tests #
- New tests verify:
- Index is present (
PRAGMA index_list) - Index is used (
EXPLAIN QUERY PLAN … USING INDEX)
- Index is present (
Example usage #
@SqlTable(tableName: 'users', version: 1)
@SqlIndex(name: 'idx_user_name', columns: ['name'])
class User { ... }
1.0.3 #
- Fixed analysis error.
- Added license