Registry / database / opensql

opensql

JSON →
library2.2.2jsnpmunverified

OpenSql is a promise-based ORM for MySQL, PostgreSQL, and Microsoft SQL Server, providing a unified API for database operations with TypeScript support. The current stable version is 2.2.2, released under MIT license. It features a simple configuration, promise-based queries, and multi-database support. Compared to alternatives like Sequelize or TypeORM, OpenSql focuses on a lightweight API and ease of use.

npm install opensql
INSTALL
IMPORT
SIG · OPENSQL
O
opensql
databasejavascriptv2.2.2
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.

OpenSql
import { OpenSql } from 'opensql'
import OpenSql from 'opensql'
Named export, not default. TypeScript types included.
Config
import { Config } from 'opensql'
Type for configuration object.
QueryResult
import { QueryResult } from 'opensql'
Type for query results.

Connects to MySQL using environment variables, runs a SELECT query, and logs the result.

import { OpenSql } from 'opensql'; const config = { host: process.env.DB_HOST ?? 'localhost', port: parseInt(process.env.DB_PORT ?? '3306'), user: process.env.DB_USER ?? 'root', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'test' }; const db = new OpenSql(config); async function main() { try { const result = await db.query('SELECT NOW() as currentTime'); console.log('Current time:', result[0].currentTime); } catch (error) { console.error('Query failed:', error); } finally { await db.end(); } } main();
Debug
Known issues
breakingIn v2.0.0, the API changed from using default export to named export `OpenSql`.
fix
Use `import { OpenSql } from 'opensql'` instead of `import OpenSql from 'opensql'`.
affects: >=2.0.0
deprecatedThe `query` method returns an array of rows, not a custom object.
fix
Access results as array elements, e.g., `result[0]`.
affects: >=1.0.0
gotchaDatabase drivers must be installed separately for each database type.
fix
Install `mysql2` for MySQL, `pg` for PostgreSQL, or `mssql` for SQL Server.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: opensql_1.OpenSql is not a constructor
Using default import with named export.
fix
Use `import { OpenSql } from 'opensql'`.
Error: Cannot find module 'mysql2'
Missing MySQL driver dependency.
fix
Run `npm install mysql2`.
Error: Connection refused: connect ECONNREFUSED 127.0.0.1:3306
MySQL server not running or wrong host/port.
fix
Check that MySQL is running and that host/port are correct in config.
Upgrade
Version history
2.2.2latest on npm
Audit
Dependencies
mysql2requiredMySQL driver for database connections
pgoptionalPostgreSQL driver for database connections
mssqloptionalMS SQL Server driver for database connections
Agent activity
4 hits · last 30 days
node
4
Resources
opensql — npm install opensql · libregistry