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

Unified Diff: lib/src/db/model_db_impl.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/db/model_db.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/db/model_db_impl.dart
diff --git a/lib/src/db/model_db_impl.dart b/lib/src/db/model_db_impl.dart
index 2a15464ddbf30d6ac2ade8e3e6484b8435ac5bf7..d4b02346c25e525b50561df3a74c23d7a9464814 100644
--- a/lib/src/db/model_db_impl.dart
+++ b/lib/src/db/model_db_impl.dart
@@ -144,11 +144,19 @@ class ModelDBImpl implements ModelDB {
String fieldNameToPropertyName(String kind, String fieldName) {
var modelDescription = _kind2ModelDesc[kind];
if (modelDescription == null) {
- throw new ArgumentError('The kind $kind is unknown.');
+ throw new ArgumentError('The kind "$kind" is unknown.');
}
return modelDescription.fieldNameToPropertyName(fieldName);
}
+ /// Converts [value] according to the [Property] named [name] in [type].
+ Object toDatastoreValue(String kind, String fieldName, Object value) {
+ var modelDescription = _kind2ModelDesc[kind];
+ if (modelDescription == null) {
+ throw new ArgumentError('The kind "$kind" is unknown.');
+ }
+ return modelDescription.encodeField(this, fieldName, value);
+ }
Iterable<_ModelDescription> get _modelDescriptions {
return _modelDesc2Type.values;
@@ -443,9 +451,16 @@ class _ModelDescription {
return _property2FieldName[propertySearchName];
}
- Object encodeField(ModelDBImpl db, String fieldName, Object value) {
+ Object encodeField(ModelDBImpl db, String fieldName, Object value,
+ {bool enforceFieldExists: true}) {
Property property = db._propertiesForModel(this)[fieldName];
- if (property != null) return property.encodeValue(db, value);
+ if (property != null) {
+ return property.encodeValue(db, value);
+ }
+ if (enforceFieldExists) {
+ throw new ArgumentError(
+ 'A field named "$fieldName" does not exist in kind "$kind".');
+ }
return null;
}
}
@@ -516,7 +531,8 @@ class _ExpandoModelDescription extends _ModelDescription {
}
Object encodeField(ModelDBImpl db, String fieldName, Object value) {
- Object primitiveValue = super.encodeField(db, fieldName, value);
+ Object primitiveValue = super.encodeField(db, fieldName, value,
+ enforceFieldExists: false);
// If superclass can't encode field, we return value here (and assume
// it's primitive)
// NOTE: Implicit assumption:
« no previous file with comments | « lib/src/db/model_db.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698