← Back to Stormify Documentation

AndroidDataSource

class AndroidDataSource(db: SQLiteDatabase, initSql: String? = null, statementCacheSize: Int = 64) : DataSource

Android KDBC implementation backed by android.database.sqlite.SQLiteDatabase.

Wraps a platform SQLite database into the KDBC DataSource interface so the Stormify ORM (and any other KDBC consumer) can run unchanged on Android. The implementation uses native SQLite primitives throughout: SQLiteStatement for INSERT/UPDATE/DELETE with proper typed bindings, SQLiteDatabase.rawQuery for SELECTs, savepoints via raw SQL for nested transactions, and the real sqlite_version() reported through DatabaseMetaData.

Usage

val db = context.openOrCreateDatabase("mydb.db", Context.MODE_PRIVATE, null)
val stormify = Stormify(AndroidDataSource(db))

The wrapped database is not owned by the data source — calling Connection.close does not close the underlying SQLiteDatabase. Lifecycle of the database is the caller's responsibility (typically tied to the Android Application lifetime).

initSql runs on every getConnection call before the connection is returned — like HikariCP's connectionInitSql. Separate more than one statement with ;; each is run in order. Typical use: AndroidDataSource(db, "PRAGMA foreign_keys = ON"). Note that Android wraps a single shared SQLiteDatabase, so the statements run once per borrow even though the underlying handle is reused.

Constructors

Link copied to clipboard
constructor(db: SQLiteDatabase, initSql: String? = null, statementCacheSize: Int = 64)

Functions

Link copied to clipboard
open override fun getConnection(): Connection

Opens and returns a new database connection. The caller is responsible for closing it.