dartapi_db 0.0.15
dartapi_db: ^0.0.15 copied to clipboard
A light weight Database helper wrapper for dartapi.
0.0.15 #
New features.
- Add
DbResult.map<T>(mapper)— maps every row toTusing a mapper function, returningList<T>. - Add
DbResult.firstAs<T>(mapper)— maps the first row toT, or returnsnullif the result is empty. - Add
DartApiDB.insertBatch(table, rows)andDbTransaction.insertBatch(table, rows)— inserts multiple rows in a singleINSERT ... VALUES (...), (...)statement. PostgreSQL returns inserted rows viaRETURNING *; MySQL and SQLite setaffectedRows. Empty list is a no-op. - Add identifier quoting to
QueryBuilder— table names and column names are now quoted correctly for each driver ("identifier"for PostgreSQL/SQLite,`identifier`for MySQL), preventing conflicts with reserved keywords. - Add runtime warning when
whereInlist exceeds 1 000 items — largeINclauses degrade performance; the warning suggests using a JOIN or temporary table instead. - Add
dryRunparameter toMigrationRunner.migrate()— prints pending migrations without applying them. Useful for CI checks and deploy previews.
0.0.14 #
Bug fixes.
- Fix
MySqlDatabase.rawQueryand_MySqlTxDB.rawQuery—DbResult.executionTimeis now populated for MySQL queries and transactions, consistent with PostgreSQL and SQLite. - Fix
SqliteDatabase.updateand_SqliteTxDB.update— WHERE-clause values are now stored under prefixed keys (w_<col>) in the positional params map, matching the PostgreSQL driver. Previously, when a column appeared in bothdataandwhere(e.g. updatingnameWHEREname = old), the map collapsed to a single entry and the second positional?was bound incorrectly, causing silent data corruption. - Fix
QueryBuilder.where(whereIn:)— throwsArgumentErrorimmediately when an empty list is passed instead of silently generating invalid SQLIN ()that fails at the database level. - Dependency upgrades:
test1.31.0 → 1.31.1,test_api0.7.11 → 0.7.12,test_core0.6.17 → 0.6.18,matcher0.12.19 → 0.12.20,analyzer12.1.0 → 13.0.0,vm_service15.1.0 → 15.2.0.
0.0.13 #
Milestone 4 — MySQL SqlDatabase Consistency.
MySqlDatabasenowextends SqlDatabaseinstead ofimplements DartApiDB—insert,select,update, anddeleteare inherited; onlyrawQuery,transaction,connect,close, andparamStyleare MySQL-specific.- Add
SqlTransactionabstract class (lib/core/sql_transaction.dart) — mirrorsSqlDatabasefor transaction-scoped operations._MySqlTxDBand_PostgresTxDBboth extend it, eliminating duplicated SQL-building in transaction callbacks. - Add
ph(String key)method toSqlDatabaseandSqlTransaction— returns:keyfor colon style (MySQL) or@keyfor named style (PostgreSQL), so all CRUD methods emit the correct placeholder automatically. PostgresDatabaseis updated to useph()in itsRETURNING *overrides;_PostgresTxDBinheritsselectfromSqlTransaction(no longer duplicated).- No SQL-building logic is duplicated across drivers or transaction classes.
- Add
test/mysql_consistency_test.dart— 17 unit tests verifying MySQL inherits correct:paramSQL fromSqlDatabasevia a stub that captures generated SQL without a live server. - Full suite: 78 tests passing.
0.0.12 #
- Upgrade
sqlite3from^2.4.0to^3.3.1— fixes deprecation warning (dispose()→close()) - Upgrade
mysql_client_plusfrom^0.0.31to^0.1.2 - Upgrade
lintsfrom^5.0.0to^6.1.0
0.0.11 #
- Add
QueryBuilder— fluent SELECT query builder returned bydb.query(table).where(column, {equals, notEquals, greaterThan, lessThan, greaterThanOrEqual, lessThanOrEqual, like, whereIn, isNull, isNotNull})— rich WHERE conditions (all AND-joined).select(columns)— restrict to specific columns instead ofSELECT *.orderBy(column, {ascending})— multi-column sorting.limit(n)/.offset(n)— offset-based pagination; SQLite emitsLIMIT -1 OFFSET nautomatically.get()→Future<DbResult>— all matching rows.first()→Future<Map<String,dynamic>?>— first row or null.count()→Future<int>— row count (ignores ORDER BY / LIMIT / OFFSET)
- Add
DbParamStyleenum (named/colon/positional) andDartApiDB.paramStylegetter — drivers declare their placeholder style;QueryBuildergenerates correct SQL automatically for all three drivers - Add
DbQueryExtensiononDartApiDB— providesdb.query(table)without circular imports
0.0.10 #
- Add
test/mysql_query_builder_test.dart— regression tests for Bug 1 (MySQLupdate()SET/WHERE parameter collision); validates thatw_prefix correctly isolates WHERE params from SET params
0.0.9 #
- Improve README: add MySQL connection example, improve clarity
0.0.8 #
- Add
DbTransactionabstract class for transaction-scoped query sessions - Add
DartApiDB.transaction<T>(callback)— runs callback in a DB transaction; commits on success, rolls back on exception- PostgreSQL: uses
Pool.runTx()(native transaction session) - MySQL: acquires a dedicated connection via
pool.withConnection()withSTART TRANSACTION/COMMIT/ROLLBACK - SQLite: uses
BEGIN/COMMIT/ROLLBACKon the same connection
- PostgreSQL: uses
- Add
SqliteDatabasedriver — fullDartApiDBimplementation backed bysqlite3 - Add
DbType.sqliteenum value - Add
DbConfig.sqlite(String path)convenience constructor; use':memory:'for in-memory databases - Add
MigrationRunner— Flyway-style SQL migration runner that tracks applied migrations in_dartapi_migrations - Add 19 tests for SQLite and MigrationRunner (no server required)
0.0.7 #
- Add connection pooling for PostgreSQL (via
Pool.withEndpoints) and MySQL (viaMySQLConnectionPool) - Add
PoolConfigclass withmaxConnections,minConnections,connectionTimeout, andidleTimeout - Add optional
poolConfigfield toDbConfig— backward compatible, defaults toPoolConfig()when omitted
0.0.6 #
- Fix
MySqlDatabase.update()parameter collision when the same column appears in both SET and WHERE clauses (WHERE params now usew_prefix internally)
0.0.5 #
- Upgrade Postgres to ^3.5.6 from ^2.6.2
0.0.4 #
- Upgrade Postgres to ^3.5.6 from ^2.6.2
0.0.3 #
- Add Code Doc
0.0.2 #
- Fix Test and Exports.
0.0.1 #
- Initial version.