Registry / database / autosql

autosql

JSON →
library1.1.1jsnpmunverified

AutoSQL is a TypeScript-powered zero-config ingestion library that automatically infers SQL schemas from JSON data and inserts it into MySQL or PostgreSQL. Version 1.1.1 supports automatic schema creation, alteration, batch inserts, and streaming with minimal configuration. It differs from traditional ORMs by requiring no model definitions or migration scripts, making it suitable for rapidly evolving data pipelines. Key features include type inference, primary key management, schema drift detection, and SSH tunneling support. The library is actively maintained, with the latest release focusing on stability and MySQL compatibility.

npm install autosql
INSTALL
IMPORT
SIG · AUTOSQL
A
autosql
databasejavascriptv1.1.1
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.

Database
import { Database } from 'autosql'
const autosql = require('autosql'); const db = new autosql.Database()
Database is a named export, not default. Requires ES module import to use.
inferTypes
import { inferTypes } from 'autosql'
const { inferTypes } = require('autosql')
inferTypes is a utility for type inference. Ensure ESM import.
DatabaseConfig
import type { DatabaseConfig } from 'autosql'
import { DatabaseConfig } from 'autosql'
DatabaseConfig is a TypeScript interface, import as type for correct typing.

Connects to a MySQL database, infers schema from JSON data, creates or alters the 'users' table, and inserts the data batch-wise using autoSQL.

import { Database } from 'autosql'; const config = { sqlDialect: 'mysql', host: process.env.DB_HOST ?? 'localhost', user: process.env.DB_USER ?? 'root', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'test', port: Number(process.env.DB_PORT ?? 3306), }; const data = [ { id: 1, name: 'Alice', created_at: '2024-01-01' }, { id: 2, name: 'Bob', created_at: '2024-01-02' }, ]; async function run() { let db: Database; try { db = Database.create(config); await db.establishConnection(); await db.autoSQL('users', data); console.log('Data inserted successfully'); } catch (err) { console.error('Error:', err); } finally { await db?.closeConnection(); } } run();
Debug
Known issues
breakingThe 'metaData' configuration field expects a specific MetadataHeader format; providing mismatched keys will cause schema creation failures.
fix
Ensure metaData object keys match table names and values conform to MetadataHeader interface (see docs).
affects: >=1.0.0
breakingDatabase.create() must be called before establishConnection(); direct instantiation via 'new Database()' is deprecated and will be removed in v2.
fix
Always use Database.create(config) to instantiate, then call .establishConnection().
affects: >=1.1.0
deprecatedThe 'insertOptions' parameter in autoInsertData is deprecated. Use autoSQL() for full workflow or manually pass options via config.
fix
Replace autoInsertData({ table, data, insertOptions }) with autoSQL(table, data) and set options in DatabaseConfig.
affects: >=1.1.0
gotchaUsing 'pgsql' as dialect value; note that configuration uses 'pgsql' not 'postgres' or 'postgresql'.
fix
Set sqlDialect: 'pgsql' for PostgreSQL, not 'postgres'.
affects: >=1.0.0
gotchaAutoSQL does not automatically drop or truncate tables; it only creates or alters. Existing rows are not deleted before insert.
fix
Manually truncate the table before running autoSQL if you need a fresh insert, or use a separate migration step.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Database.create is not a constructor
Using 'new Database(config)' instead of 'Database.create(config)'.
fix
Replace 'new Database(config)' with 'Database.create(config)'.
Error: Cannot find module 'mysql2'
Missing required database driver for MySQL dialect.
fix
Run 'npm install mysql2' to install the MySQL driver.
Error: dialect 'postgres' not supported
Using 'postgres' as dialect value instead of 'pgsql'.
fix
Set 'sqlDialect: 'pgsql'' in configuration.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
mysql2optionalRequired for MySQL connections
pgoptionalRequired for PostgreSQL connections
ssh2optionalOptional SSH tunneling support
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
autosql — npm install autosql · libregistry