Security News
OpenJS: “XZ Utils Cyberattack Likely Not an Isolated Incident”
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.
@evershop/mysql-query-builder
Advanced tools
Weekly downloads
Readme
A MySQL query builder for NodeJS.
npm install @evershop/mysql-query-builder
It implements async/await.
// var mysql = require('mysql');
// var connection = mysql.createConnection({
// host : 'localhost',
// user : 'me',
// password : 'secret',
// database : 'my_db'
// });
// connection.connect();
// connection.query('SELECT * FROM product WHERE product_id > ?', [1], function (error, results, fields) {
// if (error) throw error;
// console.log('The solution is: ', results[0].solution);
// });
const {select} = require('@evershop/mysql-query-builder')
const products = await select("*")
.from("product")
.where("product_id", ">", 1)
.execute(pool);
// var mysql = require('mysql');
// var mysql = require('mysql');
// var connection = mysql.createConnection({
// host : 'localhost',
// user : 'me',
// password : 'secret',
// database : 'my_db'
// });
// connection.query('SELECT * FROM product WHERE product_id > ? AND sku LIKE ?', [1, "sku"], function (error, results, fields) {
// if (error) throw error;
// console.log('The solution is: ', results[0].solution);
// });
const {select} = require('@evershop/mysql-query-builder')
const products = await select("*")
.from("product")
.where("product_id", ">", 1)
.and("sku", "LIKE", "sku")
.execute(pool);
// var mysql = require('mysql');
// var mysql = require('mysql');
// var connection = mysql.createConnection({
// host : 'localhost',
// user : 'me',
// password : 'secret',
// database : 'my_db'
// });
// connection.query('SELECT * FROM product WHERE (product_id > ? AND sku LIKE ?) OR price > ?', [1, "sku", 100], function (error, results, fields) {
// if (error) throw error;
// console.log('The solution is: ', results[0].solution);
// });
const {select} = require('@evershop/mysql-query-builder')
const query = select("*").from("product");
query.where("product_id", ">", 1).and("sku", "LIKE", "sku");
query.orWhere("price", ">", 100);
const products = await query.execute(pool);
// var mysql = require('mysql');
// var mysql = require('mysql');
// var connection = mysql.createConnection({
// host : 'localhost',
// user : 'me',
// password : 'secret',
// database : 'my_db'
// });
// connection.query('SELECT * FROM product LEFT JOIN price ON product.id = price.id WHERE (product_id > ? AND sku LIKE ?) OR price > ?', [1, "sku", 100], function (error, results, fields) {
// if (error) throw error;
// console.log('The solution is: ', results[0].solution);
// });
const {select} = require('@evershop/mysql-query-builder')
const query = select("*").from("product");
query.leftJoin('price').on('product.`product_id`', '=', 'price.`product_id`');
query.where("product_id", ">", 1).and("sku", "LIKE", "sku");
query.andWhere("price", ">", 100);
const products = await query.execute(pool);
user_id | name | phone | status | |
---|---|---|---|---|
1 | David | emai@email.com | 123456 | 1 |
// var mysql = require('mysql');
// var mysql = require('mysql');
// var connection = mysql.createConnection({
// host : 'localhost',
// user : 'me',
// password : 'secret',
// database : 'my_db'
// });
// connection.query('INSERT INTO user SET name=?, email=?, phone=?, status=?', ["David", "email@email.com", "123456", 1], function (error, results, fields) {
// if (error) {
// return connection.rollback(function() {
// throw error;
// });
// }
// });
const {insert} = require('@evershop/mysql-query-builder')
const query = insert("user")
.given({name: "David", email: "email@email.com", "phone": "123456", status: 1, notExistedColumn: "This will not be a part of the query"});
await query.execute(pool);
const {update} = require('@evershop/mysql-query-builder')
const query = update("user")
.given({name: "David", email: "email@email.com", "phone": "123456", status: 1, notExistedColumn: "This will not be a part of query"})
.where("user_id", "=", 1);
await query.execute(pool);
const {insert, getConnection, startTransaction, commit, rollback} = require('@evershop/mysql-query-builder');
const pool = mysql.createPool({
host: "localhost",
user: "root",
password: "123456",
database: "test",
dateStrings: true
});
// Create a connection from the pool
const connection = await getConnection(pool);
// Start a transaction
await startTransaction(connection);
try {
await insert("user")
.given({name: "David", email: "email@email.com", "phone": "123456", status: 1, notExistedColumn: "This will not be a part of the query"})
.execute(connection);
await commit(connection);
} catch(e) {
await rollback(connection);
}
All user provided data will be escaped. Please check this for more detail.
FAQs
A MySQL query builder for NodeJS
The npm package @evershop/mysql-query-builder receives a total of 2 weekly downloads. As such, @evershop/mysql-query-builder popularity was classified as not popular.
We found that @evershop/mysql-query-builder 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.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.
Company News
Come meet the Socket team at BSidesSF and RSA! We're sponsoring several fun networking events and we would love to see you there.
Security News
OSI is starting a conversation aimed at removing the excuse of the SaaS loophole for companies navigating licensing and the complexities of doing business with open source.