Permalink
Browse files

feat(mysql): add between symbol

  • Loading branch information...
XadillaX committed May 1, 2017
1 parent eae9bcc commit 5bfb0eeed1e669522a6998e36c15e4245b7e327c
Showing with 20 additions and 2 deletions.
  1. +20 −2 lib/adapters/mysql.js
@@ -29,7 +29,8 @@ const FIELD_LOGICS = {
"$lte": "<=",
"$gte": ">=",
"$like": "LIKE",
"$in": "IN"
"$in": "IN",
"$between": "BETWEEN"
};

/**
@@ -227,11 +228,13 @@ class MySQLAdapter extends Adapter {
case "$gte":
case ">=":
case "$like":
case "$between":
case "$in": {
const symbol = FIELD_LOGICS[fieldLogic];

// regard `IN` as special
if("IN" === symbol) {
// regard `IN` as special

let sql = `\`${field.column}\` IN `;
let seg = fragCond.map(value => field.restore(value));
debug(`${field.column} =>`, seg);
@@ -244,6 +247,21 @@ class MySQLAdapter extends Adapter {
sql += `(${seg.join(", ")})`;
fragments.push(sql);
break;
} else if("BETWEEN" === symbol) {
// regard `BETWEEN` as special

let sql = `\`${field.column}\` BETWEEN `;
let seg = [ field.restore(fragCond[0]), field.restore(fragCond[1]) ];
debug(`${field.column} => BEWTEEN`, seg);

if(field.type.needQuotes) {
seg = seg.map(value => `"${escaper.escape(value)}"`);
}

debug(`${field.column} => BETWEEN`, seg);
sql += `${seg[0]} AND ${seg[1]}`;
fragments.push(sql);
break;
}

let and = [];

0 comments on commit 5bfb0ee

Please sign in to comment.