make the storage collection support JS-style constraints

This commit is contained in:
Myk Melez 2009-06-18 17:26:28 -07:00
Родитель 7e2d4198f4
Коммит a1b13393a9
2 изменённых файлов: 23 добавлений и 5 удалений

Просмотреть файл

@ -900,10 +900,10 @@ let Sources = {
if (source.id) {
let constraints = [];
constraints.push({ name: "sources.id",
operator: "=",
constraints.push({ name: "source.id",
operator: "==",
value: source.id });
// FIXME: use a left join here once the SQLite bug breaking left joins to
// virtual tables has been fixed (i.e. after we upgrade to SQLite 3.5.7+).
// FIXME: reimplement this using the new non-storage-specific collections model.

Просмотреть файл

@ -144,6 +144,19 @@ StorageCollection.prototype = {
},
//**************************************************************************//
// Statement Generation
// JS to SQL property name lookup table
_properties: {
"source.id" : "sources.id"
},
// JS to SQL operator lookup table
_operators: {
"==" : "="
},
get _statement() {
let columns = [
"messages.id AS messageID",
@ -198,8 +211,13 @@ StorageCollection.prototype = {
"";
let conditions = [];
for each (let constraint in this.constraints)
conditions.push(constraint.name + " " + constraint.operator + " " + constraint.value);
for each (let { name: name, operator: operator, value: value } in this.constraints) {
conditions.push(
(name in this._properties ? this._properties[name] : name) +
(operator in this._operators ? this._operators[operator] : operator) +
value
);
}
if (conditions.length > 0)
query += " WHERE " + conditions.join(" AND ");