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.

database
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.

Only named exports; default export is not available.

import { createTable } from 'extra-sql'

ESM-only package; CommonJS require may fail depending on bundler settings.

import * as xsql from 'extra-sql'

Function names are camelCase starting with lowercase.

import { setupTable } from 'extra-sql'

Constant names are uppercase with underscores.

import { OPERATORS } from 'extra-sql'

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 footguns
gotchaPackage only generates SQL string output; it does not execute queries against a database.
gotchaCurrently only targets PostgreSQL; generated SQL syntax (e.g., `$$` for string literals, `information_schema`) may not work with other databases like MySQL or SQLite.
gotchaAll exported symbols are functions or constants; no class-based API. Attempting to instantiate with `new` will fail.
deprecatedThe `insertIntoStream` function may not be stable; its behavior could change in future versions.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
8 hits · last 30 days
gptbot
3
mj12bot
1
ahrefsbot
1
Resources