jm-ez-mysql
Overview
Easy MySQL Wrapper for NodeJS
Installation
npm install jm-ez-mysql --save
Examples
var My = ; // Init DB ConnectionMy; // Select AllMy // Select All with countMy // Select FirstMy; // InsertMy // Insert Multiple RowsMy // UpdateMy // Update FirstMy // DeleteMy // Pure MySQL Queryvar id = "'4";My ; // Pure MySQL Query as Formatted Stringvar id = "'4";My ; // Select All using prepared statementMy // Select All with count using prepared statementMy // Select First using prepared statementMy; // Update using prepared statementMy // Update First using prepared statementMy // Delete using prepared statementMy //Select Query with where conditionconst selectQuery = My;selectQuery;selectQuery; //Select Query with multiple where conditionconst selectQuery = My;selectQuery;selectQuery;selectQuery; //Select Query with multiple(AND/OR) where conditionconst selectQuery = My;selectQuery;selectQuery;selectQuery;//query : SELECT * FROM table WHERE id = 1 OR name = 'searchContent'; //Select Query with multiple(AND/OR) with multple condition where conditionconst selectQuery = My;selectQuery;selectQuery;selectQuery; //Another way to pass condition valueconst selectQuery = My;newQuery;selectQuery;selectQuery;//query: SELECT * FROM table WHERE (id = 1 OR id = 50) OR name = 'searchContent'; //Select custom fieldsconst selectQuery = My;selectQuery; // argument can be String|Array , Default is *selectQuery;//Query: SELECT name, id, data FROM table WHERE 1=1 //Use joins : // Ex1. Left Joinconst selectQuery = My;selectQuery; selectQuery; // Query: SELECT * FROM table1 as t1 LEFT JOIN table2 as t2 ON t2.t1ID = t1.id WHERE 1=1; // Ex2. Left and Right Joinconst selectQuery = My;selectQuery; selectQuery; selectQuery;//Query: SELECT * FROM table1 as t1 LEFT JOIN table2 as t2 ON t2.t1ID = t1.id RIGHT JOIN table3 as t3 ON t3.t1ID = t1.id WHERE 1=1; // Ex3. Left Join with Conditionconst selectQuery = My;selectQuery; selectQuery;//query: SELECT * FROM table as t1 LEFT JOIN table2 as t2 ON t2.t1ID = t1.id AND t2.name = 'somename' WHERE 1=1; // Ex4. Inner Join const selectQuery = My;selectQuery;selectQuery;// Query: SELECT * FROM table1 as t1 INNER JOIN table2 as t2 ON t2.t1ID = t1.id WHERE 1=1; // Ex5.const selectQuery = My;selectQuery; // third argument will join type ex. (left, right, right outer, ...), default is innerselectQuery; //Use query as countconst selectQuery = My;selectQuery; // argument can be String|Array , Default is *selectQuery;selectQuery;selectQuery; // If third argument will be true than last condition will remains and used for further process, like for count.//Qeury: SELECT name, id, data FROM table WHERE (id = 1 OR id = 50) OR name = 'searchContent' selectQuery; // argument can be any field name, default is id selectQuery;//Qeury: SELECT COUNT(table.id) as count FROM table WHERE (id = 1 OR id = 50) OR name = 'searchContent' //Use order byconst selectQuery = My;selectQuery;selectQuery;selectQuery;//Query: SELECT * FROM table WHERE 1=1 ORDER BY id ASC, name DESC //Use group byconst selectQuery = My;selectQuery; //selectQuery;//Query:SELECT * FROM table WHERE 1=1 GROUP BY id //Use Limit const selectQuery = My;selectQuery; // records want to skipselectQuery;selectQuery;//Query:SELECT * FROM table WHERE 1=1 LIMIT 2, 10 // Get Last fired Queryconsole;
License
The MIT License (MIT)