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

Unified Diff: impl/prod/raw_datastore.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: impl/prod/raw_datastore.go
diff --git a/impl/prod/raw_datastore.go b/impl/prod/raw_datastore.go
index 18a6259b50af0d4fe9d3d1158dd5250be7c67e2e..560ed4b11f94472c7ce3eb0a78a91ec24dbff4ef 100644
--- a/impl/prod/raw_datastore.go
+++ b/impl/prod/raw_datastore.go
@@ -5,7 +5,8 @@
package prod
import (
- rds "github.com/luci/gae/service/rawdatastore"
+ ds "github.com/luci/gae/service/datastore"
+ "github.com/luci/gae/service/info"
"golang.org/x/net/context"
"google.golang.org/appengine"
"google.golang.org/appengine/datastore"
@@ -14,10 +15,8 @@ import (
// useRDS adds a gae.RawDatastore implementation to context, accessible
// by gae.GetDS(c)
func useRDS(c context.Context) context.Context {
- return rds.SetFactory(c, func(ci context.Context) rds.Interface {
- // TODO(riannucci): Track namespace in a better way
- k := datastore.NewKey(ci, "kind", "", 1, nil) // get current namespace.
- return rdsImpl{ci, k.Namespace()}
+ return ds.SetRawFactory(c, func(ci context.Context) ds.RawInterface {
+ return rdsImpl{ci, info.Get(ci).GetNamespace()}
})
}
@@ -25,37 +24,37 @@ func useRDS(c context.Context) context.Context {
type queryImpl struct{ *datastore.Query }
-func (q queryImpl) Distinct() rds.Query {
+func (q queryImpl) Distinct() ds.Query {
return queryImpl{q.Query.Distinct()}
}
-func (q queryImpl) End(c rds.Cursor) rds.Query {
+func (q queryImpl) End(c ds.Cursor) ds.Query {
return queryImpl{q.Query.End(c.(datastore.Cursor))}
}
-func (q queryImpl) EventualConsistency() rds.Query {
+func (q queryImpl) EventualConsistency() ds.Query {
return queryImpl{q.Query.EventualConsistency()}
}
-func (q queryImpl) KeysOnly() rds.Query {
+func (q queryImpl) KeysOnly() ds.Query {
return queryImpl{q.Query.KeysOnly()}
}
-func (q queryImpl) Limit(limit int) rds.Query {
+func (q queryImpl) Limit(limit int) ds.Query {
return queryImpl{q.Query.Limit(limit)}
}
-func (q queryImpl) Offset(offset int) rds.Query {
+func (q queryImpl) Offset(offset int) ds.Query {
return queryImpl{q.Query.Offset(offset)}
}
-func (q queryImpl) Order(fieldName string) rds.Query {
+func (q queryImpl) Order(fieldName string) ds.Query {
return queryImpl{q.Query.Order(fieldName)}
}
-func (q queryImpl) Start(c rds.Cursor) rds.Query {
+func (q queryImpl) Start(c ds.Cursor) ds.Query {
return queryImpl{q.Query.Start(c.(datastore.Cursor))}
}
-func (q queryImpl) Ancestor(ancestor rds.Key) rds.Query {
+func (q queryImpl) Ancestor(ancestor ds.Key) ds.Query {
return queryImpl{q.Query.Ancestor(dsF2R(ancestor))}
}
-func (q queryImpl) Project(fieldNames ...string) rds.Query {
+func (q queryImpl) Project(fieldNames ...string) ds.Query {
return queryImpl{q.Query.Project(fieldNames...)}
}
-func (q queryImpl) Filter(filterStr string, value interface{}) rds.Query {
+func (q queryImpl) Filter(filterStr string, value interface{}) ds.Query {
return queryImpl{q.Query.Filter(filterStr, value)}
}
@@ -67,11 +66,11 @@ type rdsImpl struct {
ns string
}
-func (d rdsImpl) NewKey(kind, stringID string, intID int64, parent rds.Key) rds.Key {
+func (d rdsImpl) NewKey(kind, stringID string, intID int64, parent ds.Key) ds.Key {
return dsR2F(datastore.NewKey(d, kind, stringID, intID, dsF2R(parent)))
}
-func (rdsImpl) DecodeKey(encoded string) (rds.Key, error) {
+func (rdsImpl) DecodeKey(encoded string) (ds.Key, error) {
k, err := datastore.DecodeKey(encoded)
return dsR2F(k), err
}
@@ -93,18 +92,18 @@ func idxCallbacker(err error, amt int, cb func(idx int, err error)) error {
return err
}
-func (d rdsImpl) DeleteMulti(ks []rds.Key, cb rds.DeleteMultiCB) error {
+func (d rdsImpl) DeleteMulti(ks []ds.Key, cb ds.DeleteMultiCB) error {
err := datastore.DeleteMulti(d, dsMF2R(ks))
return idxCallbacker(err, len(ks), func(_ int, err error) {
cb(err)
})
}
-func (d rdsImpl) GetMulti(keys []rds.Key, cb rds.GetMultiCB) error {
+func (d rdsImpl) GetMulti(keys []ds.Key, cb ds.GetMultiCB) error {
rkeys := dsMF2R(keys)
vals := make([]datastore.PropertyLoadSaver, len(keys))
for i := range keys {
- vals[i] = &typeFilter{rds.PropertyMap{}}
+ vals[i] = &typeFilter{ds.PropertyMap{}}
}
err := datastore.GetMulti(d, rkeys, vals)
return idxCallbacker(err, len(keys), func(idx int, err error) {
@@ -112,15 +111,15 @@ func (d rdsImpl) GetMulti(keys []rds.Key, cb rds.GetMultiCB) error {
})
}
-func (d rdsImpl) PutMulti(keys []rds.Key, vals []rds.PropertyLoadSaver, cb rds.PutMultiCB) error {
+func (d rdsImpl) PutMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.PutMultiCB) error {
rkeys := dsMF2R(keys)
rvals := make([]datastore.PropertyLoadSaver, len(vals))
for i, val := range vals {
- rvals[i] = &typeFilter{val.(rds.PropertyMap)}
+ rvals[i] = &typeFilter{val}
}
rkeys, err := datastore.PutMulti(d, rkeys, vals)
return idxCallbacker(err, len(keys), func(idx int, err error) {
- k := rds.Key(nil)
+ k := ds.Key(nil)
if err == nil {
k = dsR2F(rkeys[idx])
}
@@ -128,14 +127,14 @@ func (d rdsImpl) PutMulti(keys []rds.Key, vals []rds.PropertyLoadSaver, cb rds.P
})
}
-func (d rdsImpl) NewQuery(kind string) rds.Query {
+func (d rdsImpl) NewQuery(kind string) ds.Query {
return queryImpl{datastore.NewQuery(kind)}
}
-func (d rdsImpl) Run(q rds.Query, cb rds.RunCB) error {
+func (d rdsImpl) Run(q ds.Query, cb ds.RawRunCB) error {
tf := typeFilter{}
t := q.(queryImpl).Query.Run(d)
- cfunc := func() (rds.Cursor, error) {
+ cfunc := func() (ds.Cursor, error) {
return t.Cursor()
}
for {
@@ -152,7 +151,7 @@ func (d rdsImpl) Run(q rds.Query, cb rds.RunCB) error {
}
}
-func (d rdsImpl) RunInTransaction(f func(c context.Context) error, opts *rds.TransactionOptions) error {
+func (d rdsImpl) RunInTransaction(f func(c context.Context) error, opts *ds.TransactionOptions) error {
ropts := (*datastore.TransactionOptions)(opts)
return datastore.RunInTransaction(d, f, ropts)
}

Powered by Google App Engine
This is Rietveld 408576698