Kotlin SDK Quickstart
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.
Looking for other supported sdks?
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 versionLogin to cloud.onyx.dev to create a database and an API key & secret.
Here is a minimal example schema:
{
"tables": [
{
"name": "User",
"identifier": {"name": "id", "generator": "UUID", "type": "String"},
"type": "DEFAULT",
"attributes": [
{"name": "id","type": "String","maxSize": null,"isNullable": false},
{"name": "status","type": "String","maxSize": null,"isNullable": false},
{"name": "email", ...},
{"name": "createdAt", ...}
]
}
]
}Set credentials using environment variables or a project config file.
Option A: Environment variables
export ONYX_DATABASE_ID="your-database-id"
export ONYX_DATABASE_API_KEY="key_abc"
export ONYX_DATABASE_API_SECRET="secret_xyz"Option B: Project config file (onyx-database.json)
{
"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 gen --lang kotlin --out ./generated/onyxPersist 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: