🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

nodejs-mysql-querybuilder

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodejs-mysql-querybuilder

Simple sync-mysql query builder

1.0.2
latest
Source
npm
Version published
Weekly downloads
4
33.33%
Maintainers
1
Weekly downloads
 
Created
Source

QueryBuilder

Installation

npm install nodejs-mysql-querybuilder --save

Documentation

Initialisation

const QueryBuilder = require('nodejs-mysql-querybuilder');

const db = new QueryBuilder({
	host: 'localhost',
	user: 'user',
	password: 'password',
	database: 'database'
});

db.setTable('table');
db.connect();

Select

The select method take one string parameter

db.setTable('users');
db.select('username, password')
	.where('id', 12)
	.and('mail', 'test@test.com');
db.execute();
const res = db.fetch();

Insert

The select method take an object as parameter

db.setTable('users');
db.insert({
	username: 'johndoe',
	password: 'foobar',
	mail: 'johndoe@test.com'
});

db.execute();

Update

The Update method take an object as parameter and need a where filter

db.setTable('users');
db.update({
	username: 'johndoe',
	password: 'foobar',
	mail: 'johndoe@test.com'
});

db.where('id', 12);
db.execute();

Delete

The Delete method take two parameters

db.setTable('users');
db.delete('id', 12);
db.execute();

Filters

Where

where filter is unique, you need to use and if you need another filter

db.setTable('users');
db.select('username, password').where('id', 12).execute();
let res = db.fetchAll();

And

db.setTable('users');
db.select('username, password').where('id', 12).and('mail', 'test@test.com').execute();
let res = db.fetchAll();

Or

db.setTable('users');
db.select().where('id', 12).or('mail', 'test@test.com').execute();
let res = db.fetchAll();

Join

db.setTable('users');
db.select('users.username, messages.message')
	.join('INNER', 'messages')
	.on('messages.iduser', 'users.id');

FAQs

Package last updated on 27 Dec 2022

Did you know?

Socket

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.

Install

Related posts