A simple, sane & modern ORM library for Node.js
snake_case
(for the database) and camelCase
(for JavaScript) handling.And much more - see the example below to get an idea.
Requires Node.js v4.0.0 or higher.
npm install ormur
Check out the basic example for an example of a minimal base model and an example model inheriting from it.
For an example of how you may share schema between models, check the advanced example.
The User
model defined in the above examples could be used like this,
assuming that the relevant database table exists:
const User = require('./example/basic/user');
// Create an instance
const user = new User({ name: 'Hawk', email: '[email protected]', password: 'password' });
// Persist it to the database
user.save().then(user => {
console.log(`User ${user.name} with id ${user.id} saved.`);
});
// Find users with the name "Hawk"
User.where({ name: 'Hawk' }).then(users => {
// Array of User instances.
console.log(users);
});
// Find a user by its primary key and remove it from the database
User.find(1).then(user => user.destroy());
// Or, maybe more succintly
User.destroy(1);
Documentation pending.
Ormur.find
- Find row by primary key.Ormur.where
- Find rows by attributes.Ormur.create
- Create row with attributes.Ormur.destroy
- Remove row by primary key.Ormur#validate
- Validate attributes.Ormur#save
- Insert row into database with attributes from instance.Ormur#update
- Update existing row in database with attributes from instance.Ormur#destroy
- Remove row from database by primary key of instance.Ormur#setDefaults
- Set default values to instance attributes.Ormur#merge
- Merge two objects (inheritance helper).