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

Unified Diff: impl/memory/datastore.go

Issue 1379673002: Add a NewDatastore helper function. (Closed) Base URL: https://github.com/luci/gae.git@fix_queries
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | impl/memory/datastore_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/datastore.go
diff --git a/impl/memory/datastore.go b/impl/memory/datastore.go
index 5b8581a71c8d9e6c3623086b949c3b7b613784dd..efc61d3ba5f1a13ee1ac6bc8c89a04c206a508c9 100644
--- a/impl/memory/datastore.go
+++ b/impl/memory/datastore.go
@@ -11,6 +11,7 @@ import (
"golang.org/x/net/context"
ds "github.com/luci/gae/service/datastore"
+ "github.com/luci/gae/service/info"
)
//////////////////////////////////// public ////////////////////////////////////
@@ -29,6 +30,29 @@ func useRDS(c context.Context) context.Context {
})
}
+// NewDatastore creates a new standalone memory implementation of the datastore,
+// suitable for embedding for doing in-memory data organization.
+//
+// It's configured by default with the following settings:
+// * AutoIndex(true)
+// * Consistent(true)
+// * DisableSpecialEntities(true)
+//
+// These settings can of course be changed by using the Testable() interface.
+func NewDatastore(aid, ns string) (ds.Interface, error) {
+ ctx := UseWithAppID(context.Background(), aid)
+ ctx, err := info.Get(ctx).Namespace(ns)
+ if err != nil {
+ return nil, err
+ }
+ ret := ds.Get(ctx)
+ t := ret.Testable()
Vadim Sh. 2015/09/29 20:08:36 name 'Testable' is unfortunate, considering it is
iannucci 2015/09/29 20:09:45 Yeah that occurred to me. AlterSemantics?
Vadim Sh. 2015/09/29 20:12:03 "Tweaks"? "Hacks"? :)
+ t.AutoIndex(true)
+ t.Consistent(true)
+ t.DisableSpecialEntities(true)
+ return ret, nil
+}
+
//////////////////////////////////// dsImpl ////////////////////////////////////
// dsImpl exists solely to bind the current c to the datastore data.
« no previous file with comments | « no previous file | impl/memory/datastore_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698