@lobomfz/db
v0.1.0
Published
SQLite database with Arktype schemas and typed Kysely client
Maintainers
Readme
@lobomfz/db
SQLite database with Arktype schemas and typed Kysely client.
Install
bun add @lobomfz/db arktype kyselyUsage
import { type } from "arktype";
import { Database, autoIncrement } from "@lobomfz/db";
const db = new Database({
path: "data.db",
tables: {
users: type({
id: autoIncrement(),
name: "string",
email: type("string").configure({ unique: true }),
"bio?": "string",
}),
posts: type({
id: autoIncrement(),
user_id: type("number.integer").configure({ references: "users.id", onDelete: "cascade" }),
title: "string",
tags: "string[]",
}),
},
});
// Fully typed Kysely client
await db.kysely.insertInto("users").values({ name: "John", email: "[email protected]" }).execute();
const users = await db.kysely.selectFrom("users").selectAll().execute();Features
- Tables auto-created from Arktype schemas
- Full TypeScript inference
- JSON columns with validation
- Foreign keys, unique constraints, defaults
autoIncrement()for primary keys
Column Configuration
type("string").configure({ unique: true })
type("string").configure({ default: "pending" })
type("number.integer").configure({ default: "now" }) // Unix timestamp
type("number.integer").configure({ references: "users.id", onDelete: "cascade" })onDelete options: "cascade", "set null", "restrict"
Errors
import { JsonParseError, JsonValidationError } from "@lobomfz/db";License
MIT
