Registry / database / sql-generate

sql-generate

JSON →
library1.5.0jsnpmunverified

CLI tool and API that inspects a MySQL, PostgreSQL, or MSSQL database and generates JavaScript definitions for the node-sql library. The current stable version is 1.5.0. It is released sporadically, with no fixed cadence. Key differentiator: it automates the creation of sql.define() statements by connecting directly to your database and introspecting tables and columns, saving manual schema mapping. Note: since v1.0.0, you must install the actual database drivers (mysql, pg, mssql) separately.

npm install sql-generate
INSTALL
IMPORT
SIG · SQL-GENERATE
S
sql-generate
databasejavascriptv1.5.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.

default (generateSqlDefinition)
const generateSqlDefinition = require('sql-generate');
import generateSqlDefinition from 'sql-generate';
This package is CommonJS only; there is no ESM export.
none (CLI binary)
node-sql-generate --dsn 'mysql://user:pass@localhost/db'
none (CLI binary via npx)
npx sql-generate --dsn 'mysql://user:pass@localhost/db'
npx node-sql-generate --dsn ...
npx uses the package name, not the binary name.

Shows both CLI and API usage: connecting to a MySQL database and generating sql.define() definitions.

// Install globally (CLI) or locally (API) npm install -g sql-generate # CLI usage: generate SQL definitions for a MySQL database node-sql-generate --dsn "mysql://root:password@localhost/mydb" --output-file ./definitions.js # API usage const generateSqlDefinition = require('sql-generate'); const options = { dsn: 'mysql://root:password@localhost/mydb', outputFile: './definitions.js' }; generateSqlDefinition(options, (err, result) => { if (err) throw err; console.log('Generated definitions'); });
Debug
Known issues
breakingVersion 1.0.0 removed bundled database drivers; you must install mysql, pg, or mssql separately.
fix
npm install mysql (or pg, mssql) alongside sql-generate.
affects: >=1.0.0
deprecatedThe binary name is 'node-sql-generate', not 'sql-generate'.
fix
Use 'node-sql-generate' as the command.
affects: all
gotchaThe generated code requires the 'sql' module (node-sql). Do not install the wrong 'sql' package from npm.
fix
Install 'sql' (not 'sql.js' or 'sqlite3'): npm install sql.
affects: all
gotchaPostgreSQL users must specify --schema; default is 'public'.
fix
Pass --schema if your tables are in a non-public schema.
affects: all
gotchaThe generated code uses CommonJS (require/exports). It will not work with ESM imports unless wrapped.
fix
Use require() or convert to ESM.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'mysql'
Since v1.0.0, database drivers are not bundled.
fix
npm install mysql
Error: connect ECONNREFUSED
Database server is not running or connection string is wrong.
fix
Check that the database is accessible and the DSN is correct.
Error: Cannot find module 'sql'
Generated code requires the 'sql' module, which is not installed.
fix
npm install sql
Upgrade
Version history
1.5.0latest on npm
Audit
Dependencies
sqlrequiredGenerated code depends on the sql module for query building
mysqloptionalDriver for MySQL databases (must be installed separately)
pgoptionalDriver for PostgreSQL databases (must be installed separately)
mssqloptionalDriver for MSSQL databases (must be installed separately)
Agent activity
16 hits · last 30 days
node
12
Meta
2
OpenAI (training)
1
Resources
sql-generate — npm install sql-generate · libregistry