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

Unified Diff: service/datastore/pls_impl.go

Issue 1259593005: Add 'user friendly' datastore API. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: 100% coverage of new code Created 5 years, 5 months 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
Index: service/datastore/pls_impl.go
diff --git a/service/rawdatastore/datastore_impl.go b/service/datastore/pls_impl.go
similarity index 97%
rename from service/rawdatastore/datastore_impl.go
rename to service/datastore/pls_impl.go
index 1b10daffe5676d61c1741675d052828323c13de4..9a369123c59cf58b2431ab169fa568f2638bcfea 100644
--- a/service/rawdatastore/datastore_impl.go
+++ b/service/datastore/pls_impl.go
@@ -4,7 +4,7 @@
// HEAVILY adapted from github.com/golang/appengine/datastore
-package rawdatastore
+package datastore
import (
"fmt"
@@ -359,7 +359,12 @@ func (p *structPLS) SetMeta(key string, val interface{}) (err error) {
val = Off
}
}
- p.o.Field(idx).Set(reflect.ValueOf(val))
+ f := p.o.Field(idx)
+ if val == nil {
+ f.Set(reflect.Zero(f.Type()))
+ } else {
+ f.Set(reflect.ValueOf(val))
+ }
return nil
}
@@ -369,7 +374,7 @@ var (
// The RWMutex is chosen intentionally, as the majority of access to the
// structCodecs map will be in parallel and will be to read an existing codec.
// There's no reason to serialize goroutines on every
- // gae.RawDatastore.{Get,Put}{,Multi} call.
+ // gae.Interface.{Get,Put}{,Multi} call.
structCodecsMutex sync.RWMutex
structCodecs = map[reflect.Type]*structCodec{}
)
@@ -563,6 +568,11 @@ func convertMeta(val string, t reflect.Type) (interface{}, error) {
switch t {
case typeOfString:
return val, nil
+ case typeOfKey:
+ if val != "" {
+ return nil, fmt.Errorf("key field is not allowed to have a default: %q", val)
+ }
+ return nil, nil
case typeOfInt64:
if val == "" {
return int64(0), nil

Powered by Google App Engine
This is Rietveld 408576698