Db (database) is a utility class that is intended to facilitate communications with a MySQL server.
You can chain together Db's methods to build and execute queries for you, eliminating long query strings in your code.
Set the table you wish to query.
Set the columns you wish to select.
Add a WHERE clause to your query.
(async ()=>{
const conn = new Database('localhost','user','pass','mysql');
let users = await conn.table('user').select('user').where("password_expired = 'Y'").execute().catch(console.error);
console.log(users);
})();
Add an AND clause to your query. This can be repeated as many times as desired.
Add an OR clause to your query. This can be repeated as many times as desired.
Add an ORDER BY clause to your query.
Insert a new record into the selected database and table.
(async ()=>{
const conn = new Database('localhost','user','pass','target_db');
let obj = {key:'value',key2:'value2',key3:4};
await conn.table('target_table').inset(obj).execute().catch(console.error);
console.log(users);
})();
Update a specific record from the selected database and table. Note, if not combined with a where clause, this method will update all records in your table.
(async ()=>{
const conn = new Database('localhost','user','pass','target_db');
let obj = {id:3,key:'value',key2:'value2',key3:4};
await conn.table('target_table').update(obj).where("id = " + obj.id)execute().catch(console.error);
})();
Execute the query that you have constructed.