Registry / database / sql-creator

sql-creator

JSON →
library0.54.0jsnpmunverified

SQL Creator generates SQL migration queries by diffing two ASTs (Abstract Syntax Trees) representing database schemas. Version 0.54.0 is the latest stable release. It is used to programmatically produce ALTER TABLE, CREATE TABLE, DROP TABLE, and similar statements from a 'from' and 'to' AST. It is distinct from migration tools like Knex or TypeORM because it operates purely on ASTs and does not require a specific ORM or database driver. The library focuses on schema comparison rather than executing migrations or managing versions. It supports PostgreSQL and MySQL dialects.

npm install sql-creator
INSTALL
IMPORT
SIG · SQL-CREATOR
S
sql-creator
databasejavascriptv0.54.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.

createMigrator
import { createMigrator } from 'sql-creator'
const sqlCreator = require('sql-creator')
The package is ESM-only since v0.50.0. No default export.
Migrator
import { Migrator } from 'sql-creator'
import Migrator from 'sql-creator'
Migrator is a named export, not a default export.
parseMySQL
import { parseMySQL } from 'sql-creator'
const { parseMySQL } = require('sql-creator')
parseMySQL is available as a named export. Use ESM import pattern.

Shows how to parse two SQL schemas, create a migrator, and generate migration SQL.

import { createMigrator, parseMySQL } from 'sql-creator'; const fromAST = parseMySQL(` CREATE TABLE users ( id INT PRIMARY KEY, name VARCHAR(100) ); `); const toAST = parseMySQL(` CREATE TABLE users ( id INT PRIMARY KEY, name VARCHAR(100), email VARCHAR(255) ); `); const migrator = createMigrator(fromAST, toAST); const queries = migrator.getQueries(); console.log(queries); // Output: ['ALTER TABLE users ADD COLUMN email VARCHAR(255);']
Debug
Known issues
breakingESM-only since version 0.50.0
fix
Use import syntax instead of require().
affects: >=0.50.0
breakingRemoved support for Node.js < 12 in version 0.40.0
fix
Upgrade Node.js to 12 or later.
affects: >=0.40.0
deprecatedcreateMigrator's second argument (options) is deprecated; use the builder pattern instead.
fix
Use migrator.withDialect() or similar builder methods.
affects: >=0.50.0
gotchaThe AST structure is not documented and may change between patch versions, causing breakage if you manipulate it directly.
fix
Always use the provided parse functions and avoid direct AST manipulation.
affects: *
breakingparseMySQL and parsePostgreSQL now return promises since version 0.45.0
fix
Use await when calling parse functions.
affects: >=0.45.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Trying to use import in a CommonJS file without setting type: module in package.json or using .mjs extension.
fix
Set "type": "module" in package.json or rename file to .mjs.
TypeError: sql_creator_1.createMigrator is not a function
Using require() which does not work with ESM-only packages.
fix
Switch to import syntax or use dynamic import(): import('sql-creator').then(m => ...)
Error: Cannot find module 'sql-creator'
Package not installed or path incorrect.
fix
Run npm install sql-creator (or yarn add sql-creator) and ensure node_modules is present.
Upgrade
Version history
0.54.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
14
Meta
2
OpenAI (training)
1
Resources
sql-creator — npm install sql-creator · libregistry