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 export
✓ const SnakeOrm = require('snake-orm');
✗ import SnakeOrm from 'snake-orm'; // ESM not supported
This package does not provide ESM exports. Use CommonJS require. Note the typo 'SnakeOrm' (vs 'SnakeOrm' in code).
SnakeModel
✓ const { SnakeModel } = require('snake-orm');
✗ import { SnakeModel } from 'snake-orm'; // ESM not supported
Destructure from the CommonJS require. The class name is 'SnakeModel' (capital S, capital M).
getOrCreateSnakeOrmProxy
✓ SnakeOrm.getOrCreateSnakeOrmProxy(database, username, password, config);
✗ SnakeOrm.getOrCreateSnakeOrmProxy(config); // missing database, username, password
First three arguments are required: database, username, password. Config object comes fourth.
Initializes a connection, defines a model, and performs basic find and chainable query operations.
const SnakeOrm = require('snake-orm');
SnakeOrm.getOrCreateSnakeOrmProxy('test_db', 'root', 'password', {
dialect: 'mysql',
host: 'localhost',
logger: false
});
const { SnakeModel } = SnakeOrm;
class User extends SnakeModel {
constructor() {
super(...arguments);
}
}
// Find user with primary key 1
User.find(1).then(user => console.log(user)).catch(err => console.error(err));
// Chainable query
User.where('age > ?', 18).limit(10).offset(0).then(users => console.log(users));
Errors
Common errors & fixes
TypeError: Cannot destructure property 'SnakeModel' of '(intermediate value)' as it is undefined.
The require('snake-orm') returned undefined, possibly because the package is not installed or there is a typo in the require path.
fixEnsure snake-orm is installed: npm install snake-orm. Check that the path is correct and no typos.
Error: Cannot find module 'mysql2' (or 'sqlite3')
Missing database driver dependency.
fixInstall the required driver: npm install mysql2 (or sqlite3).
TypeError: SnakeOrm.getOrCreateSnakeOrmProxy is not a function
Using import instead of require. The package does not support ESM.
fixChange to const SnakeOrm = require('snake-orm');. Audit
Dependencies
mysql2optionalMySQL driver required when using MySQL dialect.
sqlite3optionalSQLite driver required when using SQLite dialect.