зеркало из https://github.com/mozilla/snowl.git
make the storage collection support JS-style constraints
This commit is contained in:
Родитель
7e2d4198f4
Коммит
a1b13393a9
|
@ -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 ");
|
||||
|
|
Загрузка…
Ссылка в новой задаче