Skip to content

Releases

v0.5.0

Choose a tag to compare

@mekadalibrahem mekadalibrahem released this 13 Nov 19:52

Diwan Database 0.5.0

Model data: one options argument for escaped search, collection and object casts, encrypted and
hashed casts with an encrypter and a hasher you supply, binary UUID and ULID casts, and model
factories for tests and seeding. Nothing breaks; the boolean search overloads are deprecated.

Install

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

What's new

  • Search options: SearchOptions overload of the 12 escaped search methods on the query
    builder and the model builder, and a validateSearchOptions hook a grammar overrides.
  • Collection and object casts: Casts.collection() and Casts.object() read a stored JSON
    array as a List and a JSON object as a Map.
  • Encrypted casts: AttributeEncrypter, Model.attributeEncrypter() and Casts.encrypted()
    (also encrypted:array, encrypted:json, encrypted:collection, encrypted:object). Diwan does
    no cryptography: the model supplies the encrypter.
  • Hashed cast: AttributeHasher, Model.attributeHasher() and Casts.hashed(). The model
    supplies the hasher.
  • Binary ids: Casts.binaryUuid(), Casts.binaryUlid() and BinaryIds, stored as 16 bytes in
    a binary() column.
  • Factories: Factory and Sequence build models with make, create, raw and insert,
    with states, sequences, afterMaking and afterCreating hooks, related models (has,
    hasAttached, forParent) and recycle.

Deprecated

  • The 24 boolean caseSensitive search overloads and QueryGrammar.searchPattern(String, SearchWhere.Anchor, boolean), for removal in 0.6.0. Use SearchOptions.caseSensitive() in
    place of true.

See the changelog for the full
list.

Links

v0.4.0

Choose a tag to compare

@mekadalibrahem mekadalibrahem released this 11 Nov 20:03

Diwan Database 0.4.0

Schema, migrations and test support: read the schema back, shape indexes, keep two processes from
migrating at once, give each test its own database, and fix the date, time and transaction bugs apps
reported. One binary change: index and unique now return IndexDefinition, so code compiled
against 0.3.x must be recompiled; the source compiles unchanged.

Install

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

What's new

  • Schema inspection: Schema.getColumns, getColumnListing, hasColumns, getIndexListing
    and hasIndex, on SQLite, PostgreSQL and Android.
  • Index parts: partial indexes (where, whereNull, whereNotNull), asc, desc and
    collate on IndexDefinition, and Blueprint.rawIndex for an index over an expression.
  • Migration lock: SQLite and Android file databases are locked during migrations
    (FileMigrationLock, lock_wait option), so two processes do not migrate one file at once.
  • Test database modes: RefreshDatabase.rollback(...).restartingIdentities() gives the same
    PostgreSQL ids on every run; RefreshDatabase.template(...) gives each test its own copy of a
    migrated template, so tests may commit and run in parallel (PostgreSQL and SQLite files).
  • Create and drop databases: Schema.createDatabase (with a template and CopyStrategy) and
    dropDatabaseIfExists, on PostgreSQL and SQLite.
  • Blueprint extras: temporary(), table comment(text) and foreignIdFor.
  • Errors: DiwanError.table() names the table a failure concerns.
  • Time values: OffsetTime as a binding and cursor value; a PostgreSQL timezone option.

Changed and fixed

  • index and unique return IndexDefinition instead of void (recompile against 0.4.0).
  • PostgreSQL: work in a transaction aborted by a failed statement is refused with a clear error
    instead of server error 25P02.
  • Android: a commit that fails on a deferred foreign key now rolls back.
  • PostgreSQL: NaN or Infinity read from a numeric column fails with an error that names the
    column and never shows the value.

See the changelog for the full
list.

Links

v0.3.1

Choose a tag to compare

@mekadalibrahem mekadalibrahem released this 09 Nov 19:33

Diwan Database 0.3.1

A fix release for 0.3.0, from reports by apps on 0.3.0. Code written for 0.3.0 compiles and runs
unchanged.

Install

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

Fixed

  • SQLite and Android truncate with restrict keys: truncate() and truncate(List) failed with
    a foreign key violation on a table whose restrictOnDelete() key refers to its own table, so
    RefreshDatabase truncate mode left the rows behind and later test classes failed on duplicates.
    SQLite checks a restrict key row by row, even when deferred. When such a key links the listed
    tables, the deletes now run outside a transaction with foreign key enforcement off, and any row
    left pointing at an emptied table fails the truncate and undoes it. Other keys keep their cascade
    and set-null actions. Inside a transaction, such a key still fails.
  • PostgreSQL restrict violations: SQL state 23001 (restrict_violation, raised for a
    restrictOnDelete() key) is now a ForeignKeyViolationException, and
    DriverException.error().key() names the constraint, as for 23503.

Links

Diwan Database 0.3.0

Choose a tag to compare

@mekadalibrahem mekadalibrahem released this 09 Nov 09:27

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

Diwan Database 0.2.0

Choose a tag to compare

@mekadalibrahem mekadalibrahem released this 08 Nov 00:35

Diwan Database 0.2.0

Fixes and Laravel ports that apps built on 0.1.0 reached for. Every change is an addition: code
written for 0.1.0 compiles and runs unchanged.

Install

implementation("org.aristonis:diwan-database:0.2.0")
implementation("org.aristonis:diwan-database-sqlite:0.2.0")   // or -pgsql
implementation("org.aristonis:diwan-database-eloquent:0.2.0") // models, optional
implementation("org.aristonis:diwan-database-android:0.2.0")  // Android driver, optional

What's new

  • Column collation: table.string("code").collation(Collation.BINARY) gives the same byte order
    on PostgreSQL and SQLite from one migration; collation("name") names a database collation. The
    SQLite table rebuild keeps it.
  • Foreign key names: constrained(table, column, name) and references(column, name), for
    long table names that pass PostgreSQL's 63-byte limit.
  • Model builder: fillAndInsert, fillAndInsertOrIgnore and fillAndInsertGetId insert many
    rows in one statement with casts and timestamps; whereBelongsTo filters children by a parent;
    pluck(column, key) returns a map.
  • Instant cast: Casts.instant() writes an instant column in instant form whatever the
    model's timestamp format.
  • SQLite transaction mode: the transaction_mode connection option (immediate) makes two
    transactions that read then update one row wait for each other instead of failing.

Changed and fixed

  • SQLite accepts the NO_KEY_UPDATE and KEY_SHARE row locks as no-ops, as Laravel does.
  • Driver failure messages name the kind Diwan recognised and the SQLite result code, after the
    same text as before.
  • busy_timeout now reaches SQLite file databases when you set it.
  • cursorPaginate works when ordered by a date or time column.
  • A SQLite commit no longer starts a new transaction, and a commit that fails leaves the
    connection usable.

Links

Diwan Database 0.1.0

Choose a tag to compare

@mekadalibrahem mekadalibrahem released this 06 Nov 22:31

Diwan Database 0.1.0

The first release of Diwan Database: Laravel's database layer (illuminate/database), ported by
hand to Java 17 and Android. If you know Laravel's query builder, migrations and Eloquent, you
already know most of the API.

Install

implementation("org.aristonis:diwan-database:0.1.0")
implementation("org.aristonis:diwan-database-sqlite:0.1.0")   // or -pgsql
implementation("org.aristonis:diwan-database-eloquent:0.1.0") // models, optional
implementation("org.aristonis:diwan-database-android:0.1.0")  // Android driver, optional

Java 17 or later, or Android 9 (API 28) or later. SQLite and PostgreSQL. No runtime dependencies.

What's in it

  • Connections and transactions: nested transactions with savepoints, automatic retry on
    deadlocks, pretend mode, a database manager driven by configuration, and a JDBC adapter that nests
    inside a Spring transaction.
  • Query builder: Laravel's method names for reads, writes, joins, subqueries, unions, upsert,
    row locks, chunking, streaming cursors and three kinds of pagination.
  • Schema builder: every common column type, indexes, foreign keys, checks and change(). On
    SQLite, changes run as a table rebuild that keeps your rows.
  • Migrations: a migrator with batches, rollback, status, a PostgreSQL migration lock and
    optional checksums that stop a run when a migration was edited after it ran.
  • Models: casts, accessors, events and observers, scopes and soft deletes. No reflection, so
    it works with R8 on Android.
  • Relations: one-to-one, one-to-many, many-to-many with pivot writes (attach, sync,
    toggle), through, polymorphic and one-of-many relations, with eager loading, existence filters
    and aggregates.
  • Seeding and events: seeders, and listeners for queries, transactions, migrations and models.

Built to be safe

  • Every value is sent as a parameter. Error messages hide your values by default.
  • Strict transactions: a call that would run outside your transaction is refused, not run.
  • Bad data fails loudly: a stored value that does not fit its cast throws, where Laravel reads
    null, 0 or true.

Know before you start

  • upsert needs SQLite 3.24 (Android API 30 and later).
  • Open every cursor in try-with-resources. A cursor that is not closed keeps its connection.

Links