Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Unified Diff: lib/src/db/db.dart

Issue 1520863002: Implement support for converting db values to datastore values with db.Query.filter (Closed) Base URL: git@github.com:dart-lang/gcloud.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/datastore_impl.dart ('k') | lib/src/db/model_db.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/db/db.dart
diff --git a/lib/src/db/db.dart b/lib/src/db/db.dart
index 210ee2a6b54f4b7ea2097c5cce2e3c98a8f0f9bd..d1a7978339aa3a08dc6336d6c96e467dc3a0d62c 100644
--- a/lib/src/db/db.dart
+++ b/lib/src/db/db.dart
@@ -162,11 +162,30 @@ class Query {
"Invalid filter string '$filterString'.");
}
- // TODO: do value transformation on [comparisonObject]
+ var name = parts[0];
+ var comparison = parts[1];
+ var propertyName = _convertToDatastoreName(name);
+
+ // This is for backwards compatibility: We allow [datastore.Key]s for now.
+ // TODO: We should remove the condition in a major version update of
+ // `package:gcloud`.
+ if (comparisonObject is! datastore.Key) {
+ var encoded = _db.modelDB.toDatastoreValue(_kind, name, comparisonObject);
+
+ // We encode Lists as repeated properties normally, and the encoding of
+ // `['abc']` will just be `'abc'` (see [ListProperty]).
+ // But for IN filters, we need to treat them as lists.
+ if (comparison == 'IN' &&
+ comparisonObject is List &&
+ comparisonObject.length == 1 &&
+ encoded is! List) {
+ encoded = [encoded];
+ }
- var propertyName = _convertToDatastoreName(parts[0]);
+ comparisonObject = encoded;
+ }
_filters.add(new datastore.Filter(
- _relationMapping[parts[1]], propertyName, comparisonObject));
+ _relationMapping[comparison], propertyName, comparisonObject));
}
/**
« no previous file with comments | « lib/src/datastore_impl.dart ('k') | lib/src/db/model_db.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698