Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
mysql-qb
Advanced tools
Readme
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.
Unreleased (roadmap)
- INSERT ... SELECT
where
. Updated MySQL adaptervar conn = require('mysql');
conn.connect();
var qb = require('mysql-qb');
var SQL = qb.select('id, name')
.from('my_table')
.where('id', 5)
.build();
conn.query(SQL, function(error, rows){
// ... Data processing
});
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 = require('mysql-qb');
var mqb = new QueryBuilder(config);
// Query builder unlike the mysql module returns Promise. Not a callback
var query = mqb.select('id, name')
.from('my_table')
.where('id', 5)
.exec();
query.then( result => {
console.log('DB result: ', result);
}).catch(error => {
console.log('DB error: ', error);
})
You can pass to constructor mysql module connection object instead of config.
If connection 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 = require('mysql');
var connection = mysql.createConnection(config);
connection.connect();
var QueryBuilder = require('mysql-qb');
var mqb = new QueryBuilder(connection); // Passing connection.
// Query builder unlike the mysql module returns Promise. Not a callback
var query = mqb.select('id, name')
.from('my_table')
.where('id', 5)
.exec();
query.then( result => {
console.log('DB result: ', result);
}).catch(error => {
console.log('DB error: ', error);
})
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.
Method build()
returns a string and pushes last query in queries array, so you can always get it by lastQuery()
call.
All methods are described in the Methods API docs.
npm install --save mysql-qb
To run tests — where they are belong (tests/unit folder).
FAQs
MySQL query builder
The npm package mysql-qb receives a total of 43 weekly downloads. As such, mysql-qb popularity was classified as not popular.
We found that mysql-qb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.