A reworked Go API for App Engine's datastore that allows plugging in of different backends for testing.
After using the datastore.Datastore
interface for a few days I have come to the conclusion that this API should not be used. Passing around a datastore.Datastore
object between functions is a pain as most code in practice also needs a context.Context
object passed in as well. Retrofitting old code is also a pain because of this. In the end functions end up as follow:
func mutatorFunction(ctx context.Context, ds datastore.TransactionalDatastore, ...) error {
// Use datastore.
}
Or saving the datastore.Datastore
in a context:
func mutatorFunction(ctx context.Context, ...) error {
ds, ok := datastore.FromContext(ctx)
if !ok {
return errors.New("datastore not available")
}
// Use datastore.
}
Stay tuned for an updated API, with the same in memory database functionality but hopefully much easier to use in practice.