Skip to content

Diwan Database 0.3.0

Choose a tag to compare

@mekadalibrahem mekadalibrahem released this 09 Nov 09:27
· 32 commits to main since this release

Diwan Database 0.3.0

What apps built on 0.2.0 asked for: money that stays exact, searches that take user input as typed,
errors an app can act on, lock waits that end, and test support. Code written for 0.2.0 compiles and
runs unchanged.

Install

implementation("org.aristonis:diwan-database:0.3.0")
implementation("org.aristonis:diwan-database-sqlite:0.3.0")   // or -pgsql
implementation("org.aristonis:diwan-database-eloquent:0.3.0") // models, optional
implementation("org.aristonis:diwan-database-android:0.3.0")  // Android driver, optional
testImplementation("org.aristonis:diwan-database-testing:0.3.0") // test support, new

What's new

  • Test support (new artifact): RefreshDatabase.rollback(...) and .truncate(...) migrate once
    per run and reset between tests by rollback or by truncate; DatabaseAssertions gives
    assertHas, assertMissing, assertCount, assertEmpty, assertModelExists,
    assertSoftDeleted and more, never printing hidden columns.
  • Strict decimals: Casts.decimal(precision, scale) refuses a value that does not fit instead
    of rounding, with an optional RoundingMode; on SQLite it also refuses more than 15 significant
    digits. Casts.decimalText(p, s) keeps longer values exact in a text column. sumDecimal(column, scale) sums money in SQL and returns it at its scale.
  • Search user input safely: whereContains, whereStartsWith and whereEndsWith escape %
    and _, with a case-sensitive flag.
  • Errors you can act on: DriverException names the constraint and columns where the database
    says them, and carries a stable DWN- error code; check and not-null violations have their own
    kinds.
  • Lock wait limits: TransactionOptions.lockWait(Duration) per transaction,
    lock(strength, Duration) per statement on PostgreSQL, and a lock_wait connection option; a
    wait that runs out is a concurrency failure that attempts retries.
  • Schema and data reset: getTables, getTableListing, getViews, dropAllTables,
    dropAllViews, Migrator.fresh(), and truncate(List<String>[, cascade]) that empties many
    tables in one call (cascade emulated on SQLite).

Changed and fixed

  • SQLite truncate no longer fails on a database with no autoincrement table.
  • Connection.transaction(callback, attempts) is now a default method; callers are unaffected.

Links