{"id":43887,"library":"sql-creator","title":"SQL Creator","description":"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.","status":"active","version":"0.54.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install sql-creator","lang":"bash","label":"npm"},{"cmd":"yarn add sql-creator","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-creator","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is ESM-only since v0.50.0. No default export.","wrong":"const sqlCreator = require('sql-creator')","symbol":"createMigrator","correct":"import { createMigrator } from 'sql-creator'"},{"note":"Migrator is a named export, not a default export.","wrong":"import Migrator from 'sql-creator'","symbol":"Migrator","correct":"import { Migrator } from 'sql-creator'"},{"note":"parseMySQL is available as a named export. Use ESM import pattern.","wrong":"const { parseMySQL } = require('sql-creator')","symbol":"parseMySQL","correct":"import { parseMySQL } from 'sql-creator'"}],"quickstart":{"code":"import { createMigrator, parseMySQL } from 'sql-creator';\n\nconst fromAST = parseMySQL(`\n  CREATE TABLE users (\n    id INT PRIMARY KEY,\n    name VARCHAR(100)\n  );\n`);\n\nconst toAST = parseMySQL(`\n  CREATE TABLE users (\n    id INT PRIMARY KEY,\n    name VARCHAR(100),\n    email VARCHAR(255)\n  );\n`);\n\nconst migrator = createMigrator(fromAST, toAST);\nconst queries = migrator.getQueries();\nconsole.log(queries);\n// Output: ['ALTER TABLE users ADD COLUMN email VARCHAR(255);']","lang":"typescript","description":"Shows how to parse two SQL schemas, create a migrator, and generate migration SQL."},"warnings":[{"fix":"Use import syntax instead of require().","message":"ESM-only since version 0.50.0","severity":"breaking","affected_versions":">=0.50.0"},{"fix":"Upgrade Node.js to 12 or later.","message":"Removed support for Node.js < 12 in version 0.40.0","severity":"breaking","affected_versions":">=0.40.0"},{"fix":"Use migrator.withDialect() or similar builder methods.","message":"createMigrator's second argument (options) is deprecated; use the builder pattern instead.","severity":"deprecated","affected_versions":">=0.50.0"},{"fix":"Always use the provided parse functions and avoid direct AST manipulation.","message":"The AST structure is not documented and may change between patch versions, causing breakage if you manipulate it directly.","severity":"gotcha","affected_versions":"*"},{"fix":"Use await when calling parse functions.","message":"parseMySQL and parsePostgreSQL now return promises since version 0.45.0","severity":"breaking","affected_versions":">=0.45.0"}],"env_vars":null,"search_vec":"'0.54.0':20 'abstract':13 'alter':32 'ast':12,46,62 'comparison':78 'creat':34 'creator':2,4 'databas':17,71 'dialect':91 'dif':10 'distinct':49 'driver':72 'drop':36 'execut':81 'focus':75 'generat':5 'javascript':92 'knex':54 'latest':23 'librari':74 'like':53 'manag':84 'migrat':7,51,82 'mysql':90 'oper':59 'orm':69 'postgresql':88 'produc':31 'programmat':30 'pure':60 'queri':8 'rather':79 'releas':25 'repres':16 'requir':66 'schema':18,77 'similar':39 'specif':68 'sql':1,3,6 'stabl':24 'statement':40 'support':87 'syntax':14 'tabl':33,35,37 'tool':52 'tree':15 'two':11 'typeorm':56 'use':28 'version':19,85","created_at":"2026-06-05T17:01:57.353016+00:00","updated_at":"2026-06-05T17:01:57.353016+00:00","problems":[{"fix":"Set \"type\": \"module\" in package.json or rename file to .mjs.","cause":"Trying to use import in a CommonJS file without setting type: module in package.json or using .mjs extension.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Switch to import syntax or use dynamic import(): import('sql-creator').then(m => ...)","cause":"Using require() which does not work with ESM-only packages.","error":"TypeError: sql_creator_1.createMigrator is not a function"},{"fix":"Run npm install sql-creator (or yarn add sql-creator) and ensure node_modules is present.","cause":"Package not installed or path incorrect.","error":"Error: Cannot find module 'sql-creator'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"sql-creator","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}