0.0.4 • Published 8 years ago

mysql-node-query-builder v0.0.4

Weekly downloads
1
License
ISC
Repository
github
Last release
8 years ago

Installation

npm install mysql-node-query-builder --save

Usage

BASIC USAGE you need create file "db.json" from root directory. Like this

{
  "host": "localhost",
  "user": "root",
  "password": "secret",
  "database": "mysql"
}
const db = require('mysql-node-query-builder');
db.table('posts')
.where('title', 'like', '%wtf%')
.join('users', 'users.id', '=', 'posts.user_id')
.paginate(15).get().then((posts) => {
    //Do something with posts
}).catch((err) => {
    //handle error
});

Other builder
create(data)
delete(id)
update(data, id)
selectRaw('SELECT * FROM categories as category')
where('id', 5) or where('id', '<>', 5)
whereIn('id', [1,2,3,4,5])
whereNotIn('id', [1,2,3,4,5])
whereRaw('id = 5')
join('categories', 'categories.id', '=', 'posts.category_id')
leftJoin('categories', 'categories.id', '=', 'posts.category_id')
rightJoin('categories', 'categories.id', '=', 'posts.category_id')
count()
orderBy('id', 'DESC');
groupBy('id')
first() return object or bool false
get() return all row of query
Slove n + 1 query problem
ex: db.table('categories').with('horoapps', 'category_id').paginate(5).then((categories) => {
        console.log(categories);
    }));

License

2017 Giang Le.

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago