node-query/lib/drivers/Mysql.js

34 lines
751 B
JavaScript
Raw Normal View History

2015-12-07 17:03:36 -05:00
'use strict';
/**
* Driver for MySQL databases
*
* @module drivers/mysql
*/
module.exports = (function() {
delete require.cache[require.resolve('../Driver')];
2015-12-07 12:03:42 -05:00
let driver = require('../Driver'),
helpers = require('../helpers');
driver.identifierStartChar = '`';
driver.identifierEndChar = '`';
/**
2015-12-07 15:58:31 -05:00
* Set the limit clause
* @param {String} sql - SQL statement to modify
* @param {Number} limit - Maximum number of rows to fetch
* @param {Number|null} offset - Number of rows to skip
* @return {String} - Modified SQL statement
*/
driver.limit = function(sql, limit, offset) {
2015-12-07 17:03:36 -05:00
if (! helpers.isNumber(offset)) {
2015-12-07 15:58:31 -05:00
return sql += ` LIMIT ${limit}`;
}
2015-12-07 15:58:31 -05:00
return sql += ` LIMIT ${offset},${limit}`;
};
return driver;
}());