mysql-orm-promise

A promise based node.js ORM for MySQL

mysql-orm-promise

mysql-orm-promise is an ORM meant to read/modify data from your MySQL database into the node.js application.

Install

npm install mysql-orm-promise

Initialization

var MySQLORM = require('mysql-orm-promise')
MysqlORM.connection.connect({
    host     : '<hostname>',
    user     : '<username>',
    password : '<password>',
    database : '<database_name>'
})

Features

A Robust Query Interface

Generic query execution

var UserModel = MysqlORM.model('user')
// `UserModel` will now act as the model representation for the `user` table in your database
UserModel.findAll().exec().then(function(usersData){
    // userData is the array of results
})

// `findAll` also has an alias function `all`

Get results based on conditions

UserModel.where({"name": "Jack"}).exec().then(function(usersData){
    // ... handle all the Jacks here ...
})

Select the fields to be retrieved

UserModel.only(['first_name', 'last_name']).exec().then(function(usersData){
    // ... handle the results here ...
})

Pagination support

UserModel.skip(5).limit(10).exec().then(function(usersData){
    // ... handle the results here ...
})

Result Ordering(Ascending/Descending)

// Fetch data in ascending order
UserModel.orderBy('id').exec().then(function(usersData){
    // ... handle the results here ...
})

// Fetch data in descending order
UserModel.orderBy('id', true).exec().then(function(usersData){
    // ... handle the results here ...
})

Issues and Suggestions

Issues and suggestions for the plugin, can be mailed at rohit0981989[at]gmail[dot]com, or reported in Github Issues