Usage
August 23, 2026 · View on GitHub
DBFlow maps Kotlin types to SQLite. You declare a @Database and @Tables. The compiler plugin generates:
{Name}_Database— concrete database +DBCreator- Model companions —
User.namecolumn properties,select from User, and the runtimeModelAdapter(User.Companion as ModelAdapter<User>) {Name}_Adapterhelpers — internalTableOps, binders, and property getters wired into companions
Work through generated adapters on the database instance. Reads and writes are suspend and run on the database’s transaction dispatcher.
db.writableTransaction {
userAdapter.save(User(name = "Ada"))
val ada = (userAdapter.select() where (User.name eq "Ada")).single()
}
Concepts
| Topic | Notes |
|---|---|
| Install | Gradle plugin, version catalog, generated sources |
| Databases | Open, settings, platforms |
| Models | Tables, keys, columns |
| Writes | save / insert / update / delete |
| Queries | select(), list(), single() |
| Relationships | Foreign keys, one-to-many, many-to-many |
| Migrations | Versioned schema changes |
| Observability | Flow on table changes |
Android-only extras: LiveData, Paging, RxJava, SQLCipher.