MySQL Query builder
Designed to make SQL-queries easier to use. With this builder you don't have to write raw-queries. In this version you can build simple SQL-queries: SELECT (with joins), CREATE, UPDATE, DELETE.
I'm using this builder for my projects so it updates few times a week. It is not stable for now and very young. v1.0 release is planned for September 1st.
- INSERT ... SELECT
- 0.7.3 - Added UNION, LIMIT by default is empty array, Fixed tests
- 0.7.2 - Fixes and new features in
where. Updated MySQL adapter
More detailed usage:
var conn = ;conn;var qb = ;var SQL = qb;conn;
As builder and executor
Passing db config
You can pass config in nodejs mysql format: More info on mysql package page. Query builder will create new connection and execute query.
var config =host: '127.0.0.1'user: 'root'password: 'mySecurePassword123'database: 'MyDB';var QueryBuilder = ;var mqb = config;// Query builder unlike the mysql module returns Promise. Not a callbackvar query = mqb;query
Passing db connection
You can pass to constructor mysql module connection object instead of config.
state == 'disconnected' builder will try to get config from connection object and reconnect automatically.
var config =host: '127.0.0.1'user: 'root'password: 'mySecurePassword123'database: 'MyDB';var mysql = ;var connection = mysql;connection;var QueryBuilder = ;var mqb = connection; // Passing connection.// Query builder unlike the mysql module returns Promise. Not a callbackvar query = mqb;query
Order of method calls in pipeline doesn't matter. They all return
this so you can use them UNTIL
build() method is called. After that query is immutable.
build() returns a string and pushes last query in queries array, so you can always get it by
All methods are described in the Methods API docs.
npm install --save mysql-qb
To run tests — where they are belong (tests/unit folder).