Registry / database / imago-sql

imago-sql

JSON →
library4.8.0jsnpmunverified

Small library to work with Azure SQL and MySQL via a single interface. Based on the mssql module. Current stable version is 4.8.0. Released under MIT license. Key differentiator: provides a unified API for Azure SQL and MySQL, with connection pooling and parameterized queries. Well-suited for projects requiring both database engines without changing code. Relies on mssql for Azure SQL and mysql2 for MySQL.

npm install imago-sql
INSTALL
IMPORT
SIG · IMAGO-SQL
I
imago-sql
databasejavascriptv4.8.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.

Sql
const Sql = require('imago-sql');
import Sql from 'imago-sql';
CommonJS only; no ESM. Use require.
sql.db.mssql
sql.db.mssql.NVarChar
require('mssql').NVarChar
Do not require mssql separately; use the internal instance to avoid duplicate driver errors.
new Sql(connectionString, options)
let sql = new Sql('mssql://...');
new Sql({ connectionString: '...' })
Constructor expects a string connection URL, not an object.

Connects to Azure SQL using connection string and fetches all rows from a table.

const Sql = require('imago-sql'); async function main() { const sql = new Sql(process.env.DB_CONNECTION_STRING ?? ''); await sql.connection; // ensure connection const results = await sql.selectAll('My_Table_Name'); console.log(results); } main().catch(console.error);
Debug
Known issues
gotchaDo not require mssql separately; it causes duplicate driver errors.
fix
Use sql.db.mssql for column types.
affects: >=1.0
gotchaConnection object is async; must await sql.connection before queries.
fix
Use await sql.connection before any query.
affects: >=1.0
deprecatedMinimum Node.js version is 8.9 as of latest version.
fix
Update to Node.js >= 8.9 or use lower version if needed.
affects: >=4.0
gotchaMySQL engine requires engine: 'mysql' option
fix
Pass { engine: 'mysql' } as second argument to constructor.
affects: >=1.0
Errors
Common errors & fixes
ReferenceError: sql is not defined
sql variable not in scope
fix
Ensure sql is declared and accessible in the function.
Cannot find module 'imago-sql'
Package not installed
fix
Run npm install imago-sql --save
TypeError: sql.connection.then is not a function
sql.connection not awaited
fix
Use await sql.connection
Upgrade
Version history
4.8.0latest on npm
Audit
Dependencies
mssqlrequiredAzure SQL driver
mysql2optionalMySQL driver
Agent activity
11 hits · last 30 days
node
10
Bingbot
1
Resources
imago-sql — npm install imago-sql · libregistry