The @onyx.dev/onyx-database SDK is a zero-dependency, strict-typed client for the Onyx Cloud Database. It ships ESM & CJS builds, includes a credential resolver, and offers optional schema code generation so your queries stay table-safe.
Use this SDK to connect from Node.js (18+) or edge runtimes such as Cloudflare Workers. The recommended flow is: create an organization and database in the cloud console, create API keys, then configure credentials locally.
1) Install the SDK from npm:
npm i @onyx.dev/onyx-database
2) Install the Onyx CLI (for schema pulls & 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
Generate TypeScript types
Install the CLI, pull your schema, and generate table-safe types and a tables enum.
onyx schema get onyx.schema.json
onyx gen
Initialize with env vars or pass explicit config:
import { onyx } from '@onyx.dev/onyx-database';
const db = onyx.init({ databaseId: 'YOUR_DATABASE_ID' });const db = onyx.init({
baseUrl: 'https://api.onyx.dev',
databaseId: 'YOUR_DATABASE_ID',
apiKey: 'YOUR_KEY',
apiSecret: 'YOUR_SECRET',
partition: 'tenantA',
requestLoggingEnabled: true,
responseLoggingEnabled: true,
});The builder-pattern API mirrors the README examples. Here is a quick save and list flow for aUser table:
import { onyx, eq, contains, asc } from '@onyx.dev/onyx-database';
const db = onyx.init();
await db.save('User', {
id: 'user_123',
email: 'alice@example.com',
status: 'active',
});
const activeUsers = await db
.from('User')
.where(eq('status', 'active'))
.and(contains('email', '@example.com'))
.orderBy(asc('createdAt'))
.limit(25)
.list();