Registry / database / sql-schema-generator

sql-schema-generator

JSON →
library0.25.2jsnpmunverified

A declarative relational database SQL schema generator for PostgreSQL that abstracts boilerplate and enforces best practices like insert-only temporal database design, optimal data types, and naming conventions. Current stable version is 0.25.2, with an inactive release cadence (last release in 2020). It generates static and versioned tables, mapping tables, upsert functions, and current-version views to support event-driven, domain-driven design patterns. Unlike ORMs or migration tools, it produces raw SQL files under user control, avoiding lock-in and allowing custom modifications.

npm install sql-schema-generator
INSTALL
IMPORT
SIG · SQL-SCHEMA-GENERAT
S
sql-schema-generator
databasejavascriptv0.25.2
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.

generateSchema
✓ import { generateSchema } from 'sql-schema-generator';
✗ const generateSchema = require('sql-schema-generator');
ESM only; no default export.
SqlEntity
✓ import { SqlEntity } from 'sql-schema-generator';
TypeScript type for entity definition objects.
cli
✓ import { cli } from 'sql-schema-generator';
✗ import { run } from 'sql-schema-generator';
Main CLI entry point; run via `npx sql-schema-generator`.

Generates SQL schema for a 'user' entity with static and updatable properties, outputting CREATE TABLE statements.

import { generateSchema } from 'sql-schema-generator'; const entities = [{ name: 'user', properties: { email: { type: 'string', unique: true }, name: { type: 'string', required: true }, }, updatableProperties: ['name'], }]; const sql = generateSchema(entities); console.log(sql);
Debug
Known issues
breakingThe `generateSchema` function now returns a string instead of an object with sql keys in v1.0.0.
fix
Update to v1.0.0+ and use the string directly.
affects: <1.0.0
gotchaEntity names are case-sensitive; references must match exactly.
fix
Use quoted identifiers in SQL if case mixing is needed.
affects: >=0.1.0
gotchaAll foreign key columns must end with `_id` or `_id` suffix.
fix
Rename reference columns to match the naming convention.
affects: >=0.1.0
deprecatedThe `array` property type is deprecated since v0.20.0; use `mapping` entity pattern instead.
fix
Define a separate mapping table entity instead of array properties.
affects: >=0.20.0
Errors
Common errors & fixes
TypeError: generateSchema is not a function
Using default import instead of named import.
fix
Use `import { generateSchema } from 'sql-schema-generator';`
Error: property 'email' must have a type defined
Missing 'type' field in property definition.
fix
Add type: 'string' (or appropriate type) to all properties.
SyntaxError: Unexpected identifier at line 1
Generated SQL may contain reserved keywords used as identifiers without quoting.
fix
Use double-quoted identifiers for reserved words like 'user'.
Upgrade
Version history
0.25.2latest on npm
Audit
Dependencies
oclifoptionalCLI framework for command-line interface
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
sql-schema-generator — npm install sql-schema-generator · libregistry