Registry / database / sojs-mysql

sojs-mysql

JSON →
library0.1.6jsnpmunverified

A simple MySQL database utility built on the sojs framework (v0.1.6). Provides a fluent query builder for generating SQL statements programmatically with support for SELECT, INSERT, UPDATE, DELETE, JOIN, GROUP BY, HAVING, ORDER BY, LIMIT, WHERE conditions (including Django-like operators: __like, __lt, __gt, __in, etc.), nested conditions via callbacks, and transaction execution. Returns Promises for async/await usage. Release cadence is low (no recent updates). Differentiator: integrates with sojs inversion-of-control container and provides a DSL similar to Django ORM for condition building.

npm install sojs-mysql
INSTALL
IMPORT
SIG · SOJS-MYSQL
S
sojs-mysql
databasejavascriptv0.1.6
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.

sojs
require('sojs')
import sojs from 'sojs'
sojs is not an ES module; use require() to load it.
DB
var DB = sojs.create('sojs.mysql.db', options);
var DB = require('sojs-mysql')(options);
DB must be created via sojs.create with the module ID 'sojs.mysql.db'; direct require does not work.
Query
var query = DB.table('users');
var query = new Query();
Query instances are obtained via DB.table(), not constructed directly.

Shows how to require sojs, create a DB instance, build a SELECT query with conditions and ordering, and execute asynchronously.

require('sojs'); var options = { connection: { host: 'localhost', port: 3306, user: 'root', password: process.env.DB_PASSWORD ?? '', database: 'test' } }; var DB = sojs.create('sojs.mysql.db', options); async function getUsers() { try { var users = await DB.table('users') .select(['id', 'name']) .where('age__gt', 18) .orderBy('name', 'asc') .get() .execute(); console.log(users); } catch (err) { console.error(err); } } getUsers();
Debug
Known issues
gotchasojs must be required before using sojs-mysql; otherwise the global 'sojs' object will not exist.
fix
Add require('sojs'); at the top of your application.
affects: all
gotchaThe execute() method returns a sojs.promise, not a native Promise. If you try to use .then() without requiring sojs, it may fail.
fix
Ensure sojs is required before any execute() calls, or convert to native Promise if needed.
affects: all
gotchaThe .limit() method must be called after .orderBy() to generate correct SQL; the library appends LIMIT after ORDER BY only if limit is called last.
fix
Chain .orderBy() before .limit().
affects: all
gotchaWhen using .insert(), .update(), or .delete(), you must call .execute() to actually run the query; the query builder returns itself until .execute() is called.
fix
Always chain .execute() after constructing the query.
affects: all
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'create')
sojs is not required before calling sojs.create.
fix
Add require('sojs'); at the top of your file.
sojs.create is not a function
sojs is not loaded correctly; possibly using ES import instead of require.
fix
Use require('sojs') instead of import.
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server is not running or connection options are incorrect.
fix
Ensure MySQL is running and host/port/user/password are correct.
Upgrade
Version history
0.1.6latest on npm
Audit
Dependencies
sojsrequiredRequired as peer dependency; package uses sojs.create to instantiate DB and relies on sojs.promise
Agent activity
11 hits · last 30 days
node
8
Meta
2
Resources
sojs-mysql — npm install sojs-mysql · libregistry