Registry / database / klay-kiln-sql

klay-kiln-sql

JSON →
library1.2.0jsnpmunverified

klay-kiln-sql v1.2.0 is a Kiln extension that generates SQL model schemas and migrations from Klay entity definitions. It produces idiomatic DDL for PostgreSQL, SQLite, and MySQL, supporting indexes, foreign keys, and type mappings. Released on a monthly cadence, it integrates with Klay's Kiln code generation pipeline, differentiating itself by offering a schema-first approach with type-safe TypeScript output.

npm install klay-kiln-sql
INSTALL
IMPORT
SIG · KLAY-KILN-SQL
K
klay-kiln-sql
databasejavascriptv1.2.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.

generateSQL
import { generateSQL } from 'klay-kiln-sql'
const generateSQL = require('klay-kiln-sql')
This package is ESM-only; CJS require() will not work.
type SQLDialect
import type { SQLDialect } from 'klay-kiln-sql'
import { SQLDialect } from 'klay-kiln-sql'
SQLDialect is a type-only export and should be imported with `import type` to avoid runtime errors.
generateSQL
const { generateSQL } = await import('klay-kiln-sql')
const generateSQL = require('klay-kiln-sql/generateSQL')
Dynamic import path suffix 'generateSQL' is incorrect; use default export from package root.

Shows how to define a Klay model and generate PostgreSQL DDL using generateSQL.

import { generateSQL } from 'klay-kiln-sql'; import { Model } from 'klay'; const userModel = new Model('User', { fields: { id: { type: 'uuid', primaryKey: true }, name: { type: 'string', required: true }, email: { type: 'string', unique: true }, }, indexes: [{ fields: ['email'] }], }); const sql = generateSQL(userModel, { dialect: 'postgresql' }); console.log(sql); // CREATE TABLE "User" ( // "id" UUID PRIMARY KEY, // "name" VARCHAR(255) NOT NULL, // "email" VARCHAR(255) UNIQUE // );
Debug
Known issues
breakingIn v1.0.0 the `dialect` option was renamed from 'postgres' to 'postgresql'.
fix
Use dialect: 'postgresql' instead of 'postgres'.
affects: <1.0.0
deprecatedThe `generateSQL` function now returns a string instead of an object with `statements` array. The old format is deprecated.
fix
Use directly as a string; if you need individual statements split by semicolons.
affects: >=1.2.0
gotchaEnum fields are not supported in SQLite dialect; they will be ignored if dialect is 'sqlite'.
fix
Use check constraints or JSON fields for SQLite enum workarounds.
affects: >=1.0.0
gotchaForeign key names are auto-generated and may not be stable across re-generation; do not rely on them in migrations.
fix
Manually name foreign keys using the `foreignKeyName` option on relations.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: generateSQL is not a function
CommonJS require() used for an ESM-only package.
fix
Use import { generateSQL } from 'klay-kiln-sql' or dynamic import.
Unsupported dialect: 'postgres'. Did you mean 'postgresql'?
The dialect option was 'postgres' which is invalid since v1.0.0.
fix
Use dialect: 'postgresql'.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
klayrequiredRequired peer dependency for model definitions
klay-kilnrequiredRequired peer dependency for Kiln code generation pipeline
Agent activity
4 hits · last 30 days
node
4
Resources
klay-kiln-sql — npm install klay-kiln-sql · libregistry