MySQL ORM for node.js
npm install ziti
The API documentation is available at http://ziti.ewdl.org/ including a guide and many examples.
var ziti = require('ziti');
var Address = require('./address');
var Photo = require('./photo');
var Language = require('./language');
var User = ziti.define('User', {
name: ziti.String().unique(),
age: ziti.Int().default(18),
address: Address, // One to One relationship
photos: [ Photo ], // One to Many relationship
langs: [ Language, 'UserLanguage' ] // Many to Many relationship
});
module.exports = User;
ziti.configure({
host: 'localhost',
user: 'root',
password: '',
database: 'ziti_test',
debug: true,
});
ziti.sync().then(function () {
// All tables have been created
});
User.save({ name: 'alex' }) // A new user named 'alex' is created, age is 18 by default
.then(function (user) {
return user.update({ age: 28 }); // His age is updated to 28
}).then(function (user) {
console.log(user.raw()); // { name: 'alex', age: 28 }
return user.remove(); // The user is removed from database
}).then(function (user) {
// ...
});
For more information, you can read the Guide
Tests results are available.
However, if you want to run tests on your own, first take a look at the config file to use your own test server.
export MYSQL_HOST=localhost
export MYSQL_USER=root
export MYSQL_DATABASE=ziti_test
npm test