Repository navigation
Releases
v0.5.0
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 supportWhat's new
- Search options:
SearchOptionsoverload of the 12 escaped search methods on the query
builder and the model builder, and avalidateSearchOptionshook a grammar overrides. - Collection and object casts:
Casts.collection()andCasts.object()read a stored JSON
array as aListand a JSON object as aMap. - Encrypted casts:
AttributeEncrypter,Model.attributeEncrypter()andCasts.encrypted()
(alsoencrypted:array,encrypted:json,encrypted:collection,encrypted:object). Diwan does
no cryptography: the model supplies the encrypter. - Hashed cast:
AttributeHasher,Model.attributeHasher()andCasts.hashed(). The model
supplies the hasher. - Binary ids:
Casts.binaryUuid(),Casts.binaryUlid()andBinaryIds, stored as 16 bytes in
abinary()column. - Factories:
FactoryandSequencebuild models withmake,create,rawandinsert,
with states, sequences,afterMakingandafterCreatinghooks, related models (has,
hasAttached,forParent) andrecycle.
Deprecated
- The 24
boolean caseSensitivesearch overloads andQueryGrammar.searchPattern(String, SearchWhere.Anchor, boolean), for removal in 0.6.0. UseSearchOptions.caseSensitive()in
place oftrue.
See the changelog for the full
list.
Links
- Documentation: https://aristonis.org/open-source/diwan-database/docs/main/home
- Full changelog: CHANGELOG.md
- Report a security problem privately: SECURITY.md
v0.4.0
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 supportWhat's new
- Schema inspection:
Schema.getColumns,getColumnListing,hasColumns,getIndexListing
andhasIndex, on SQLite, PostgreSQL and Android. - Index parts: partial indexes (
where,whereNull,whereNotNull),asc,descand
collateonIndexDefinition, andBlueprint.rawIndexfor an index over an expression. - Migration lock: SQLite and Android file databases are locked during migrations
(FileMigrationLock,lock_waitoption), 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 andCopyStrategy) and
dropDatabaseIfExists, on PostgreSQL and SQLite. - Blueprint extras:
temporary(), tablecomment(text)andforeignIdFor. - Errors:
DiwanError.table()names the table a failure concerns. - Time values:
OffsetTimeas a binding and cursor value; a PostgreSQLtimezoneoption.
Changed and fixed
indexanduniquereturnIndexDefinitioninstead ofvoid(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:
NaNorInfinityread from anumericcolumn fails with an error that names the
column and never shows the value.
See the changelog for the full
list.
Links
- Documentation: https://aristonis.org/open-source/diwan-database/docs/main/home
- Full changelog: CHANGELOG.md
- Report a security problem privately: SECURITY.md
v0.3.1
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 supportFixed
- SQLite and Android truncate with restrict keys:
truncate()andtruncate(List)failed with
a foreign key violation on a table whoserestrictOnDelete()key refers to its own table, so
RefreshDatabasetruncate 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 aForeignKeyViolationException, and
DriverException.error().key()names the constraint, as for 23503.
Links
- Documentation: https://aristonis.org/open-source/diwan-database/docs/main/home
- Full changelog: CHANGELOG.md
- Report a security problem privately: SECURITY.md
Diwan Database 0.3.0
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, newWhat's new
- Test support (new artifact):
RefreshDatabase.rollback(...)and.truncate(...)migrate once
per run and reset between tests by rollback or by truncate;DatabaseAssertionsgives
assertHas,assertMissing,assertCount,assertEmpty,assertModelExists,
assertSoftDeletedand more, never printing hidden columns. - Strict decimals:
Casts.decimal(precision, scale)refuses a value that does not fit instead
of rounding, with an optionalRoundingMode; 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,whereStartsWithandwhereEndsWithescape%
and_, with a case-sensitive flag. - Errors you can act on:
DriverExceptionnames the constraint and columns where the database
says them, and carries a stableDWN-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 alock_waitconnection option; a
wait that runs out is a concurrency failure thatattemptsretries. - Schema and data reset:
getTables,getTableListing,getViews,dropAllTables,
dropAllViews,Migrator.fresh(), andtruncate(List<String>[, cascade])that empties many
tables in one call (cascade emulated on SQLite).
Changed and fixed
- SQLite
truncateno longer fails on a database with no autoincrement table. Connection.transaction(callback, attempts)is now a default method; callers are unaffected.
Links
- Documentation: https://aristonis.org/open-source/diwan-database/docs/main/home
- Full changelog: CHANGELOG.md
- Report a security problem privately: SECURITY.md
Diwan Database 0.2.0
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, optionalWhat'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)andreferences(column, name), for
long table names that pass PostgreSQL's 63-byte limit. - Model builder:
fillAndInsert,fillAndInsertOrIgnoreandfillAndInsertGetIdinsert many
rows in one statement with casts and timestamps;whereBelongsTofilters children by a parent;
pluck(column, key)returns a map. - Instant cast:
Casts.instant()writes aninstantcolumn in instant form whatever the
model's timestamp format. - SQLite transaction mode: the
transaction_modeconnection 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_UPDATEandKEY_SHARErow 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_timeoutnow reaches SQLite file databases when you set it.cursorPaginateworks 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
- Documentation: https://aristonis.org/open-source/diwan-database/docs/main/home
- Full changelog: CHANGELOG.md
- Report a security problem privately: SECURITY.md
Diwan Database 0.1.0
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, optionalJava 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,0ortrue.
Know before you start
upsertneeds 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
- Documentation: https://aristonis.org/open-source/diwan-database/docs/main/home
- Differences from Laravel: https://aristonis.org/open-source/diwan-database/docs/main/differences-from-laravel
- Full changelog: CHANGELOG.md
- Report a security problem privately: SECURITY.md