Registry / database / simple-sql-model

simple-sql-model

JSON →
library0.9.4jsnpmunverified

A lightweight, Rails-style model wrapper around the `sql` library for Node.js. Version 0.9.4 provides CRUD operations, query methods (findOne, findMany, count), hooks (before/after create/update/destroy), and foreign key reference expansion. It relies on ES6+ features (async/await, classes) and requires Node >=4.8.1. The package is explicitly marked as unstable and not recommended for production use. It is database-agnostic, supporting any SQL dialect that the `sql` module supports (e.g., PostgreSQL, MySQL). Release cadence is irregular; the last commit was in 2019.

npm install simple-sql-model
INSTALL
IMPORT
SIG · SIMPLE-SQL-MODEL
S
simple-sql-model
databasejavascriptv0.9.4
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.

Model
const Model = require('simple-sql-model')
import Model from 'simple-sql-model'
Package uses CommonJS, not ESM. No default export; module.exports = Model class.
Model (with ES6 import)
import Model = require('simple-sql-model')
For TypeScript or ESM environments, use `import Model = require('simple-sql-model')` or `const Model = require('simple-sql-model')`. No named exports.
Model.configure
const Model = require('simple-sql-model') Model.configure({ connection, table, columns })
Model.configure({ connection: conn, table: 'users', columns: ['id', 'name'], references: { ... } })
configure() takes an object with required `connection`, `table`, `columns` and optional `references`. Works on subclasses as static method.

Quickstart: connect to PostgreSQL, define a User model with columns, create a record and query by ID.

const pgp = require('pg-promise')() const Connection = require('pg-promise') const Model = require('simple-sql-model') const connection = Connection({ database: process.env.DB_NAME ?? 'test', user: process.env.DB_USER ?? 'test', password: process.env.DB_PASS ?? '', host: process.env.DB_HOST ?? 'localhost', port: Number(process.env.DB_PORT ?? 5432), }) class User extends Model {} User.configure({ connection, table: 'users', columns: ['id', 'name', 'email'], }) async function run() { await User.create({ name: 'Alice', email: 'alice@example.com' }) const user = await User.findOne(1) console.log(user) } run().catch(console.error)
Debug
Known issues
gotchaPackage is considered unstable and not recommended for production use as per README.
fix
Use a more mature ORM like Sequelize, Knex.js, or TypeORM for production applications.
affects: >=0.0.0
breakingRequires Node >=4.8.1 and ES6 features (async/await, classes). Older Node versions will not work.
fix
Use Node 7.8+ or transpile with Babel.
affects: >=0.0.0
gotchaDependency on the `sql` module; the returned connection must provide a Promise-returning `query` method. Not all database adapters are compatible.
fix
Ensure your database library's connection object has a `query` method returning a Promise. For pg-promise, use `pgp()`; for mysql, use a promise wrapper.
affects: >=0.0.0
deprecatedNo updates since 2019; the package may be effectively abandoned. Last commit was over 4 years ago.
fix
Consider migrating to actively maintained alternatives.
affects: >0.9.4
Errors
Common errors & fixes
Cannot find module 'sql'
Missing peer dependency `sql`.
fix
npm install sql
connection.query is not a function
The provided connection object does not have a Promise-returning `query` method.
fix
Use a compatible database library such as `pg-promise` or `mysql2/promise`.
Model is not a constructor
Using ES module import syntax incorrectly (e.g., `import Model from 'simple-sql-model'`).
fix
Use CommonJS require: `const Model = require('simple-sql-model')`
Upgrade
Version history
0.9.4latest on npm
Audit
Dependencies
sqlrequiredCore dependency providing SQL dialect support and query building.
Agent activity
9 hits · last 30 days
node
8
Meta
1
Resources
simple-sql-model — npm install simple-sql-model · libregistry