Registry / database / sand-mysql-simple

sand-mysql-simple

JSON →
library0.3.11jsnpmunverified

A minimalist MySQL Model extension for Sand.js, providing a simple ORM-like wrapper around node-mysql2. Version 0.3.11 is the latest stable release. The package extends Sand.js models with table mappings, insert/update helpers, and query building. It requires node-mysql2 and Sand.js framework. Differentiator: lightweight, no heavy ORM features, tightly coupled with Sand.js ecosystem.

npm install sand-mysql-simple
INSTALL
IMPORT
SIG · SAND-MYSQL-SIMPLE
S
sand-mysql-simple
databasejavascriptv0.3.11
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.

default
var mysqlSimple = require('sand-mysql-simple');
import mysqlSimple from 'sand-mysql-simple';
CommonJS only; no ESM support
Model
var Model = require('sand-mysql-simple').Model;
require('sand-mysql-simple').model;
Case-sensitive: Model, not model
Models
require('sand-mysql-simple')
Main module is the mysqlSimple object; models are accessed via sand.mysqlSimple.models

Shows how to initialize sand-mysql-simple with Sand.js, use a model to fetch a user by ID.

var mysqlSimple = require('sand-mysql-simple'); var sand = require('sand')(); sand .use(mysqlSimple, {modelsPath: __dirname + '/models'}) .start(); sand.mysqlSimple.models.User.getById(1, function(err, user) { if (err) return console.error(err); console.log(user.email); });
Debug
Known issues
gotchaModel.extend() requires a table property; if omitted, queries will fail silently.
fix
Always define table: 'your_table_name' in the model definition.
affects: >=0.0.0
gotchaModels must be loaded via sand.mysqlSimple.models, not directly from require().
fix
Use sand.mysqlSimple.models.User instead of require('./models/User').
affects: >=0.0.0
deprecatedThe .values() method pattern is deprecated; use .getInsert() directly.
fix
Define getInsert() as a method that returns {query, values} object.
affects: >=0.3.0
Errors
Common errors & fixes
TypeError: sand.mysqlSimple is undefined
sand-mysql-simple not loaded in Sand.js.
fix
Ensure you call sand.use(mysqlSimple, {modelsPath: '...'}) before sand.start().
Error: Cannot find module 'sand-mysql'
Missing peer dependency sand-mysql.
fix
Run: npm install sand-mysql
TypeError: Object #<Object> has no method 'extend'
Incorrect import: using default export instead of .Model.
fix
Use require('sand-mysql-simple').Model.extend({...});
Upgrade
Version history
0.3.11latest on npm
Audit
Dependencies
sand-mysqlrequiredpeer dependency for MySQL queries
Agent activity
12 hits · last 30 days
node
10
Meta
1
Resources
sand-mysql-simple — npm install sand-mysql-simple · libregistry