Registry / database / extra-sql

extra-sql

JSON →
library1.1.12jsnpmunverified

A utility library for generating SQL commands programmatically, primarily targeting PostgreSQL. Version 1.1.12 supports table creation, data insertion, text search with tsquery, and table setup sequences. It generates SQL strings rather than executing them, making it useful for database migration tools, seed scripts, and query builders. Key differentiators include support for full-text search operators like `plainto_tsquery` and streaming inserts. Updates are infrequent. Ships TypeScript type definitions.

npm install extra-sql
INSTALL
IMPORT
SIG · EXTRA-SQL
E
extra-sql
databasejavascriptv1.1.12
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.

createTable
import { createTable } from 'extra-sql'
import createTable from 'extra-sql'
Only named exports; default export is not available.
xsql
import * as xsql from 'extra-sql'
const xsql = require('extra-sql')
ESM-only package; CommonJS require may fail depending on bundler settings.
setupTable
import { setupTable } from 'extra-sql'
import { SetupTable } from 'extra-sql'
Function names are camelCase starting with lowercase.
OPERATORS
import { OPERATORS } from 'extra-sql'
import { operators } from 'extra-sql'
Constant names are uppercase with underscores.

Shows how to generate SQL commands for checking table existence, creating tables with data, and performing full-text search using extra-sql.

import * as xsql from 'extra-sql'; // Generate SQL to check if a table exists const checkSql = xsql.tableExists('users'); console.log(checkSql); // → SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name='users'); // Generate SQL to create a table and insert data const [createSql, insertSql] = xsql.setupTable('food', { code: 'TEXT', name: 'TEXT' }, [ { code: 'F1', name: 'Mango' }, { code: 'F2', name: 'Lychee' } ]); console.log(createSql); // → CREATE TABLE IF NOT EXISTS "food" ("code" TEXT, "name" TEXT); console.log(insertSql); // → INSERT INTO "food" ("code", "name") VALUES // → ($$F1$$, $$Mango$$), // → ($$F2$$, $$Lychee$$); // Generate full-text search query const searchSql = xsql.selectTsquery('articles', 'quick brown fox'); console.log(searchSql); // → SELECT * FROM "articles" WHERE "tsvector" @@ plainto_tsquery('quick brown fox');
Debug
Known issues
gotchaPackage only generates SQL string output; it does not execute queries against a database.
fix
Pass the generated SQL to a database driver like `pg` or `mysql2` for execution.
affects: >=0.0.0
gotchaCurrently only targets PostgreSQL; generated SQL syntax (e.g., `$$` for string literals, `information_schema`) may not work with other databases like MySQL or SQLite.
fix
Use database-specific libraries or adapt outputs for other RDBMS.
affects: >=0.0.0
gotchaAll exported symbols are functions or constants; no class-based API. Attempting to instantiate with `new` will fail.
fix
Use function calls directly; do not use `new xsql.createTable(...)`.
affects: >=0.0.0
deprecatedThe `insertIntoStream` function may not be stable; its behavior could change in future versions.
fix
Monitor the package documentation for updates; consider implementing custom streaming inserts.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: xsql.createTable is not a function
Using default import instead of named import, or CommonJS require with ESM package.
fix
Use named import: `import { createTable } from 'extra-sql'` or `import * as xsql from 'extra-sql'`.
SyntaxError: Unexpected token 'export'
Trying to require an ES module in a CommonJS context without transpilation.
fix
Use `import` syntax or set `"type": "module"` in package.json, or use dynamic import: `const xsql = await import('extra-sql')`.
Cannot find module 'extra-sql'
Package not installed or not in node_modules.
fix
Run `npm install extra-sql` or `yarn add extra-sql`.
Upgrade
Version history
1.1.12latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
extra-sql — npm install extra-sql · libregistry