0.3.1 • Published 10 years ago

ziti v0.3.1

Weekly downloads
3
License
BSD
Repository
github
Last release
10 years ago

ziti

MySQL ORM for node.js

npm Travis branch npm npm Documentation Status Dependency Status

Installation

npm install ziti

The API documentation is available at http://ziti.ewdl.org/ including a guide and many examples.

Define your Models in separate files

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;

Configure & synchronize your models

ziti.configure({
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'ziti_test',
    debug: true,
});

ziti.sync().then(function () {
    // All tables have been created
});

Play with your models anywhere

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

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
0.3.1

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago