zsql
SQL generator for node.js modeled after Zend_Db_Select. Intended for use with easy-mysql
Overview
The query generation is separated into two parts: query and params. You can
access the string query and params array for all objects using
Query.toString()
and Query.params()
The Query.all()
function returns an array of the query and parameters, and
optionally a callback. Typically you would use easy-mysql like so:
zsql ;
The getAll/getOne/execute functions are just proxies for easy-mysql:
this_mysqlexecute;
Below is provided various examples and the resultant SQL and parameters that would be passed into easy-mysql.
Examples
Select
zsql all;
'SELECT * FROM `tableName` WHERE `columnName` = ? && columnName2 > ? && `columnName3` IN (?, ?) ORDER BY `columnName4` ASC LIMIT ?, ?' 1 2 3 4 20 5
Insert
zsql value'columnName' 1 value'columnName2' zsql all;
'INSERT INTO `tableName` (`columnName`, `columnName2`) VALUES (?, NOW())' 1
Delete
zsql all;
'DELETE FROM `tableName` WHERE `columnName` = ? LIMIT ?' 112358 1
Update
zsql all;
'UPDATE `tableName` SET `columnName1` = ? , `columnName2` = columnName2 + 1 , `columnName3` = ? WHERE `columnName4` = ? LIMIT ?' 314 'value' 159 2
Todo
- escape/interpolate support
- node-mysql support