https://github.com/androidpoet/kdb
https://github.com/androidpoet/kdb
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/androidpoet/kdb
- Owner: AndroidPoet
- License: mit
- Created: 2026-05-07T04:43:57.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-05-07T05:46:44.000Z (about 1 month ago)
- Last Synced: 2026-05-07T07:14:02.052Z (about 1 month ago)
- Language: Kotlin
- Size: 104 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# KDB: Kotlin Multiplatform SQLite Wrapper
KDB is a lightweight, type-safe SQLite wrapper for Kotlin Multiplatform.
## Modules
| Module | Description |
| :--- | :--- |
| `kdb` | Core library (driver + schema + query + paging + client API) |
| `kdb-paging3` | Optional Paging 3 integration |
## API Design
- Primary API returns `KdbResult`:
- `open`, `migrate`, `close`
- `insert`, `updateById`, `deleteById`, `getById`, `list`
- Convenience `suspend` background APIs throw on failure:
- `openOrThrow`, `migrateOrThrow`, `closeOrThrow`
- `insertOrThrow`, `updateByIdOrThrow`, `deleteByIdOrThrow`, `getByIdOrThrow`, `listOrThrow`
- Transaction helper:
- `suspend fun tx { ... }`
## Configuration
```kotlin
val kdb = createKdb(driver) {
entities(Task.serializer())
// optional, default: Dispatchers.Default
// dispatcher = Dispatchers.IO
}
```
## Quick Start (Result-first)
```kotlin
@Serializable
data class Task(val id: Long, val title: String, val done: Boolean)
val driver = CommonKdbDriver("my_app.db")
val kdb = createKdb(driver) {
entities(Task.serializer())
}
kdb.open()
kdb.migrate(
migration(1) {
createTable("task")
// or raw SQL when needed:
// sql("CREATE INDEX IF NOT EXISTS idx_task_done ON task(done)")
}
)
kdb.insert(Task(1, "Ship KDB", false))
kdb.updateById(1, Task(1, "Ship KDB v1", false))
val one = kdb.getById(1)
kdb.deleteById(1)
val page = kdb.list(limit = 20, afterId = null) { it.id }
```
## Convenience (Suspend + Throwing)
```kotlin
kdb.openOrThrow()
kdb.insertOrThrow(Task(2, "A", false))
val page = kdb.listOrThrow(limit = 20) { it.id }
kdb.tx {
insert(Task(3, "B", false)).getOrThrow()
insert(Task(4, "C", false)).getOrThrow()
}
```
## License
KDB is licensed under the MIT License. See [LICENSE](LICENSE).