Kotlin SDK
Connect to your Onyx Cloud Database with generated Kotlin models and a typed client. Install the dependency, set credentials, generate code with the Onyx CLI, then save and query with IDE autocomplete.
Connect to your Onyx Cloud Database with generated Kotlin models and a typed client. Install the dependency, set credentials, generate code with the Onyx CLI, then save and query with IDE autocomplete.
Target a cloud database with typed models and keep your schema in sync via the Onyx CLI.
Add the dependency to your build:
repositories {
mavenCentral()
}
dependencies {
implementation("dev.onyx:onyx-database:3.8.6")
}Install the Onyx CLI for schema pulls and codegen:
# Homebrew (macOS) brew tap OnyxDevTools/onyx-cli brew install onyx-cli # Or install directly curl -fsSL https://raw.githubusercontent.com/OnyxDevTools/onyx-cli/main/scripts/install.sh | bash onyx version
Create an API key in Onyx Database, then either set environment variables or place an onyx-database.json in your project root.
Option A: Environment variables (preferred)
export ONYX_DATABASE_ID="db_123" export ONYX_DATABASE_BASE_URL="https://api.onyx.dev" export ONYX_DATABASE_API_KEY="key_abc" export ONYX_DATABASE_API_SECRET="secret_xyz"
Option B: Project config file
{
"databaseId": "db_123",
"baseUrl": "https://api.onyx.dev",
"apiKey": "key_abc",
"apiSecret": "secret_xyz"
}Pull the schema and generate Kotlin models + table helpers:
onyx schema get onyx.schema.json onyx gen --lang kotlin --out ./generated/onyx
Persist and query entities with the Kotlin SDK:
fun main() {
val db = onyx.init<Any>() // resolves credentials from env/config
db.save(User(
id = "user_123",
name = "John Doe",
email = "john@example.com"
))
val users = db
.from<User>()
.where("email" eq "john@example.com")
.list<User>()
println(users)
}If you have any questions or need assistance: