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.name column properties, select from User, and the runtime ModelAdapter (User.Companion as ModelAdapter<User>)
  • {Name}_Adapter helpers — internal TableOps, 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

TopicNotes
InstallGradle plugin, version catalog, generated sources
DatabasesOpen, settings, platforms
ModelsTables, keys, columns
Writessave / insert / update / delete
Queriesselect(), list(), single()
RelationshipsForeign keys, one-to-many, many-to-many
MigrationsVersioned schema changes
ObservabilityFlow on table changes

Android-only extras: LiveData, Paging, RxJava, SQLCipher.