Skip to content

Latest commit

 

History

History
32 lines (25 loc) · 1.43 KB

README.md

File metadata and controls

32 lines (25 loc) · 1.43 KB

Usage

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

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.