Skip to content

Latest commit

 

History

History
548 lines (442 loc) · 13.5 KB

JSDOC.md

File metadata and controls

548 lines (442 loc) · 13.5 KB

Functions

clear()MySQL

Clear current values in Query Builder

select(key, as)MySQL

Add select parameter

from(table_name)MySQL

Add table name to select from

where(column, value, condition, refrence)MySQL

Add where parameter

whereGroupStart(refrence)MySQL

Grouping where with brackets

set(column, value)MySQL

Add set into update

value(column, value)MySQL

Add value to insert / replace

insert(table)MySQL

Insert query

update(table)MySQL

Update query

replace(table)MySQL

Replace query

delete(table)MySQL

Delete query

innerJoin(table)MySQL

Add inner join to select

leftJoin(table)MySQL

Add left join to select

on(table)MySQL

Set columns of join

query()string

Return generated query based on current data

values()Array.<(string|number)>

Get value array based on current data

exec(start_transaction)MySQLResult

Execute query based on current data

commit()boolean

Commit current queries. You need to use .exec(true)

rollback(error)boolean

Rollback current queries. You need to use .exec(true)

config(config)

Configure MySQL server and database info

initialize()

Initialize MySQL pool manually. It will automatically initiate. You don't have to use it manually.

getConnection()Object

Get new connection from MySQL pool

beginTransaction(connection)Object

Begin new transaction If you give connection, it will start transaction on given connection. else it will create new connection and return it.

rollback(connection)Object

Rollback transaction

commit(connection)Object

Commit transaction

execute(sql, timeout, values, connection, rollback)MySQLResult

Execute query

escape(str)string

Escape strings for use in queries

Typedefs

MySQLResult : Object
MySQLConfig : Object

clear() ⇒ MySQL

Clear current values in Query Builder

Kind: global function
Example

db.clear();

select(key, as) ⇒ MySQL

Add select parameter

Kind: global function

Param Type Description
key string Column name
as string | number Used as select as [?]

Example

db.select('username', 'uname'); // username AS uname

from(table_name) ⇒ MySQL

Add table name to select from

Kind: global function

Param Type Description
table_name string Table name

Example

// SELECT * FROM test
db
 .select('*')
 .from('test');

where(column, value, condition, refrence) ⇒ MySQL

Add where parameter

Kind: global function
Default: AND

Param Type Description
column string Column name
value string | number Value to check
condition string Condition to where (=, <, >, !=, <=, >=)
refrence string Referenced to previous where

Example

// SELECT * FROM test WHERE name = ?
db
 .from('test')
 .where('name', 'test');

Example

// SELECT * FROM test WHERE price > ?
db
 .from('test')
 .where('price', 30, '>');

Example

// SELECT * FROM test WHERE price > ? AND name = ?
db
 .from('test')
 .where('price', 30, '>')
 .where('name', 'test');

Example

// SELECT * FROM test WHERE price > ? OR name = ?
db
 .from('test')
 .where('price', 30, '>')
 .where('name', 'test', '=', 'OR');

whereGroupStart(refrence) ⇒ MySQL

Grouping where with brackets

Kind: global function

Param Type Description
refrence string Referenced to previous where

Example

// SELECT * FROM test WHERE price = ? AND (name = ? OR name = ?)
db
 .from('test')
 .where('price', 30)
 .whereGroupStart()
 .where('name', 't1')
 .where('name', 't2')
 .whereGroupEnd();

Example

// SELECT * FROM test WHERE price = ? OR (name = ? OR name = ?)
db
 .from('test')
 .where('price', 30)
 .whereGroupStart('OR')
 .where('name', 't1')
 .where('name', 't2')
 .whereGroupEnd();

set(column, value) ⇒ MySQL

Add set into update

Kind: global function

Param Type Description
column string Column name
value string | number Value to set

value(column, value) ⇒ MySQL

Add value to insert / replace

Kind: global function

Param Type Description
column string Column name
value string | number Value

insert(table) ⇒ MySQL

Insert query

Kind: global function

Param Type Description
table string Table name

Example

// INSERT INTO test (name, age) VALUES (?, ?)
db
 .insert('test')
 .value('name', 'John')
 .value('age', 21);

update(table) ⇒ MySQL

Update query

Kind: global function

Param Type Description
table string Table name

Example

// UPDATE test SET name = ?, age = ? WHERE id = ?
db
 .update('test')
 .set('name', 'John')
 .set('age', 21)
 .where('id', 1);

replace(table) ⇒ MySQL

Replace query

Kind: global function

Param Type Description
table string Table name

Example

// REPLACE INTO test (name, age) VALUES (?, ?)
db
 .replace('test')
 .value('name', 'John')
 .value('age', 21);

delete(table) ⇒ MySQL

Delete query

Kind: global function

Param Type Description
table string Table name

Example

// DELETE FROM test WHERE id = ?
db
 .delete('test')
 .where('id', 1);

innerJoin(table) ⇒ MySQL

Add inner join to select

Kind: global function

Param Type Description
table string Table name

Example

// SELECT * FROM test INNER JOIN profile ON test.id = profile.tid WHERE 1
db
 .from('test')
 .innerJoin('profile')
 .on('test.id', 'profile.tId');

leftJoin(table) ⇒ MySQL

Add left join to select

Kind: global function

Param Type Description
table string Table name

Example

// SELECT * FROM test LEFT JOIN profile ON test.id = profile.tid WHERE 1
db
 .from('test')
 .leftJoin('profile')
 .on('test.id', 'profile.tId');

on(table) ⇒ MySQL

Set columns of join

Kind: global function

Param Type Description
table string Table name

Example

// SELECT * FROM test INNER JOIN profile ON test.id = profile.tid WHERE 1
db
 .from('test')
 .innerJoin('profile')
 .on('test.id', 'profile.tId');

query() ⇒ string

Return generated query based on current data

Kind: global function
Example

// returns => 'SELECT * FROM test INNER JOIN profile ON test.id = profile.tid WHERE 1'
db
 .from('test')
 .innerJoin('profile')
 .on('test.id', 'profile.tId')
 .query();

values() ⇒ Array.<(string|number)>

Get value array based on current data

Kind: global function
Example

// ['John', 21, 1]
db
 .update('test')
 .set('name', 'John')
 .set('age', 21)
 .where('id', 1)
 .values();

exec(start_transaction) ⇒ MySQLResult

Execute query based on current data

Kind: global function

Param Type Description
start_transaction boolean If true, MySQL will start new transaction.

commit() ⇒ boolean

Commit current queries. You need to use .exec(true)

Kind: global function

rollback(error) ⇒ boolean

Rollback current queries. You need to use .exec(true)

Kind: global function

Param Type Description
error Error Error will throw after rollback.

config(config)

Configure MySQL server and database info

Kind: global function

Param Type Description
config MySQLConfig Config Data

initialize()

Initialize MySQL pool manually. It will automatically initiate. You don't have to use it manually.

Kind: global function

getConnection() ⇒ Object

Get new connection from MySQL pool

Kind: global function
Returns: Object - MySQL Connection

beginTransaction(connection) ⇒ Object

Begin new transaction If you give connection, it will start transaction on given connection. else it will create new connection and return it.

Kind: global function
Returns: Object - connection MySQL Connection

Param Type Description
connection Object MySQL Connection

rollback(connection) ⇒ Object

Rollback transaction

Kind: global function
Returns: Object - connection MySQL Connection

Param Type Description
connection Object MySQL Connection

commit(connection) ⇒ Object

Commit transaction

Kind: global function
Returns: Object - connection MySQL Connection

Param Type Description
connection Object MySQL Connection

execute(sql, timeout, values, connection, rollback) ⇒ MySQLResult

Execute query

Kind: global function

Param Type Description
sql string Query
timeout number Timeout for query execution (default: 40000) = 40 mins.
values Array.<(string|number)> Values for query Question marks (?)
connection Object If connection given it will be used. else it will get new one from pool and execute.
rollback boolean If true it will rollback on faliure

escape(str) ⇒ string

Escape strings for use in queries

Kind: global function

Param Type Description
str string String to escape

MySQLResult : Object

Kind: global typedef
Properties

Name Type Description
results Array.<string> Array of results of query
fields Array.<string> Array of columns in result

MySQLConfig : Object

Kind: global typedef
Properties

Name Type Description
host string Hostname of MySQL Server (default: 'localhost')
port number Port of MySQL Server (default: 3306)
user string Username of MySQL Server (default: 'root')
password string Password of MySQL Server (default: '')
database string Name of the database