Registry / database / kysely-sqlite-builder

kysely-sqlite-builder

JSON →
library1.0.0jsnpmunverified

Utility layer for Kysely on SQLite that provides table schema inference, auto migration, auto-generated createdAt/updatedAt columns, soft delete support, WITHOUT ROWID, auto serialization/deserialization, precompiled queries, pagination, auto-nested transactions via savepoints, enhanced logging, and typesafe SQLite3 pragma. Current stable version is 1.0.0, requires Kysely >= 0.28.0. Ships TypeScript types. Differentiators from raw Kysely: schema-based table definitions, automatic migration generation, and built-in utility features like soft delete and pagination.

npm install kysely-sqlite-builder
INSTALL
IMPORT
SIG · KYSELY-SQLITE-BUIL
K
kysely-sqlite-builder
databasejavascriptv1.0.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.

SqliteBuilder
import { SqliteBuilder } from 'kysely-sqlite-builder'
const { SqliteBuilder } = require('kysely-sqlite-builder')
Package is ESM-only (no CommonJS exports). For CommonJS, use dynamic import or transpile.
defineTable
import { defineTable } from 'kysely-sqlite-builder/schema'
import { defineTable } from 'kysely-sqlite-builder'
defineTable is exported from the subpath 'kysely-sqlite-builder/schema', not the main entry.
InferDatabase
import type { InferDatabase } from 'kysely-sqlite-builder/schema'
InferDatabase is a type export; use import type to avoid runtime overhead. It is not available as a value.

Creates a SQLite database using SqliteBuilder with schema-defined tables, auto-migration, and built-in logging.

import { SqliteBuilder } from 'kysely-sqlite-builder' import { defineTable, column, DataType, InferDatabase } from 'kysely-sqlite-builder/schema' import { useMigrator } from 'kysely-sqlite-builder/migrator' import Database from 'better-sqlite3' import { SqliteDialect, FileMigrationProvider } from 'kysely' const testTable = defineTable({ columns: { id: column.increments(), name: column.string({ notNull: true }), metadata: column.object({ defaultTo: {} }), }, primary: 'id', createAt: true, updateAt: true, softDelete: true, }) const DBSchema = { test: testTable } const db = new SqliteBuilder<InferDatabase<typeof DBSchema>>({ dialect: new SqliteDialect({ database: new Database(':memory:'), }), logger: console, onQuery: true, }) await db.syncDB(useMigrator(new FileMigrationProvider('./migrations'), {}))
Debug
Known issues
breakingRequires Kysely >= 0.28.0. Older versions are incompatible.
fix
Upgrade Kysely to at least 0.28.0.
affects: >=1.0.0
deprecatedUse of `kysely-sqlite-builder/schema` subpath may change in future versions; prefer explicit imports.
fix
Monitor release notes for import path changes.
affects: >=1.0.0
gotchadefineTable is not exported from the main entry point 'kysely-sqlite-builder'. It must be imported from 'kysely-sqlite-builder/schema'.
fix
Change import to 'import { defineTable } from 'kysely-sqlite-builder/schema''.
affects: >=1.0.0
gotchaSqliteBuilder is not compatible with Kysely instances created directly from 'new Kysely()'. You must use SqliteBuilder as the main database instance.
fix
Use SqliteBuilder instead of Kysely constructor.
affects: >=1.0.0
gotchaAuto-generated columns (createdAt, updateAt, softDelete) are added by defineTable, but they are not automatically kept in sync if you modify the table definition later. You must re-run syncDB to add or remove them.
fix
Run db.syncDB() after modifying table schemas.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: SqliteBuilder is not a constructor
Importing SqliteBuilder incorrectly or using CommonJS require on an ESM-only package.
fix
Use ESM import: import { SqliteBuilder } from 'kysely-sqlite-builder'
Module not found: Can't resolve 'kysely-sqlite-builder/schema'
Typo or wrong subpath; correct path is 'kysely-sqlite-builder/schema'.
fix
Ensure import path is exact: 'kysely-sqlite-builder/schema'
The inferred type of 'db' may not be correct because of a misconfigured database type argument.
Missing InferDatabase generic type parameter on SqliteBuilder.
fix
Use new SqliteBuilder<InferDatabase<typeof DBSchema>>({...})
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
kyselyrequiredKysely is the core query builder; this package is a utility layer on top of it.
Agent activity
6 hits · last 30 days
node
6
Resources
kysely-sqlite-builder — npm install kysely-sqlite-builder · libregistry