Skip to content

Diwan Database 0.1.0

Choose a tag to compare

@mekadalibrahem mekadalibrahem released this 06 Nov 22:31
· 59 commits to main since this release

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