Permalink
Browse files

feat: makeLimit in mysql adapter

  • Loading branch information...
XadillaX committed Aug 22, 2016
1 parent c998ca4 commit a6518055620c28aff80eb3e29908795480d65ff7
Showing with 43 additions and 0 deletions.
  1. +11 −0 lib/adapters/mysql.js
  2. +32 −0 test/adapters/mysql.js
@@ -357,6 +357,10 @@ class MySQLAdapter extends Adapter {
return order.join(", ");
}

makeLimit(model, limit) {
return limit.map(l => parseInt(l) || 0).join(", ");
}

makeFind(model, options) {
let fields = options.fields;
if(!fields || !fields.length) {
@@ -385,6 +389,13 @@ class MySQLAdapter extends Adapter {
}
}

if(options.limit && options.limit.length) {
const limit = this.makeLimit(model, options.limit);
if(limit) {
sql += ` LIMIT ${limit}`;
}
}

return sql;
}

@@ -331,5 +331,37 @@ describe("🐣 adapters/mysql", function() {
}
});
});

describe(`${name} makeLimit`, function() {
const toshihiko = new Toshihiko("mysql", {
username: "root",
password: "",
database: "toshihiko",
charset: "utf8mb4_general_ci"
});
const adapter = toshihiko.adapter;
const model = toshihiko.define("test", common.COMMON_SCHEMA);

after(function() {
adapter.mysql.end();
});


it("should generate - 1", function() {
let sql;

sql = adapter.makeLimit(model, [ 12489, 4783 ]);
sql.should.equal("12489, 4783");

sql = adapter.makeLimit(model, [ 389 ]);
sql.should.equal("389");

sql = adapter.makeLimit(model, [ "4389", "98347" ]);
sql.should.equal("4389, 98347");

sql = adapter.makeLimit(model, [ "dsklj", "dsa" ]);
sql.should.equal("0, 0");
});
});
});
});

0 comments on commit a651805

Please sign in to comment.