Registry / database / sqlite-zod-orm

sqlite-zod-orm

JSON →
library3.27.0jsnpmunverified

Type-safe SQLite ORM for Bun runtime, current stable version 3.27.0. Released frequently (multiple updates per month). Uses Zod schemas to define models, provides a fluent query builder with automatic join inference and relationship handling. Differentiators: tightly integrated with Bun's native SQLite, eliminates raw SQL entirely, auto-generates typed relationships from Zod schemas, and supports migrations. Compared to Drizzle ORM (SQL-first) or Prisma (separate schema), it uses Zod for both validation and schema definition, reducing boilerplate.

npm install sqlite-zod-orm
INSTALL
IMPORT
SIG · SQLITE-ZOD-ORM
S
sqlite-zod-orm
databasejavascriptv3.27.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Model
import { Model } from 'sqlite-zod-orm'
const Model = require('sqlite-zod-orm')
ESM-only; CommonJS not supported. Provides the base class for defining models.
defineTable
import { defineTable } from 'sqlite-zod-orm'
Use to define a table with a Zod schema. Exported as named export.
z
import { z } from 'zod'
Zod is a peer dependency; import separately to define schemas.
query
import { query } from 'sqlite-zod-orm'
import { db } from 'sqlite-zod-orm'
Query builder is exported as `query`, not `db`.

Defines a User table with Zod schema, creates a model, and performs a typed query.

import { Model, defineTable, query } from 'sqlite-zod-orm'; import { z } from 'zod'; const UserSchema = z.object({ id: z.number(), name: z.string(), email: z.string().email(), }); const User = defineTable('users', UserSchema); class UserModel extends Model(User) { // custom methods } const users = await query(UserModel) .where({ email: 'user@example.com' }) .select(); console.log(users);
Debug
Known issues
breakingBreaking change: v3 removed CommonJS support; ESM-only.
fix
Use ES modules (import/export) and Bun runtime.
affects: >=3.0.0
breakingRenamed 'Table' export to 'defineTable' in v3.
fix
Replace 'Table' with 'defineTable' in all imports.
affects: >=3.0.0
gotchaQuery builder methods are async; must be awaited.
fix
Always use 'await' or '.then()' on query results.
affects: >=1.0.0
gotchaRelationships are inferred automatically; manual configuration may override incorrectly.
fix
Ensure foreign key columns follow naming convention 'tableId'.
affects: >=1.0.0
deprecatedThe 'orderBy' method uses a string argument; object syntax is deprecated.
fix
Use object format: { column: 'asc' | 'desc' }.
affects: >=2.5.0
Errors
Common errors & fixes
TypeError: Cannot find module 'sqlite-zod-orm' or its corresponding type declarations.
Missing package installation or TypeScript not configured for ESM.
fix
Install with 'bun add sqlite-zod-orm' and set 'type': 'module' in tsconfig.json.
SQLITE_ERROR: no such table: users
Table not created; migrations not run or schema mismatched.
fix
Run migration or manually create table using '.create()' on model.
TypeError: query(...).where is not a function
Incorrect import; likely importing 'query' from wrong package or using old API.
fix
Ensure 'query' is imported from 'sqlite-zod-orm' and use as shown in quickstart.
ZodError: [ { "code": "custom", "message": "Invalid email", ... } ]
Validation failed at runtime due to Zod schema constraints.
fix
Check input data matches the defined Zod schema; adjust schema if needed.
Upgrade
Version history
3.27.0latest on npm
Audit
Dependencies
typescriptrequiredpeer dependency: TypeScript required for full type safety
zodrequiredcore: used for schema definitions and validation
bunrequiredruntime: only works with Bun >=1.0.0
Agent activity
14 hits · last 30 days
node
10
Meta
2
Amazon
1
OpenAI (training)
1
Resources
sqlite-zod-orm — npm install sqlite-zod-orm · libregistry