OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "errors" | 8 "errors" |
9 "fmt" | 9 "fmt" |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // suitable for embedding for doing in-memory data organization. | 47 // suitable for embedding for doing in-memory data organization. |
48 // | 48 // |
49 // It's configured by default with the following settings: | 49 // It's configured by default with the following settings: |
50 // * AutoIndex(true) | 50 // * AutoIndex(true) |
51 // * Consistent(true) | 51 // * Consistent(true) |
52 // * DisableSpecialEntities(true) | 52 // * DisableSpecialEntities(true) |
53 // | 53 // |
54 // These settings can of course be changed by using the Testable() interface. | 54 // These settings can of course be changed by using the Testable() interface. |
55 func NewDatastore(aid, ns string) (ds.Interface, error) { | 55 func NewDatastore(aid, ns string) (ds.Interface, error) { |
56 ctx := UseWithAppID(context.Background(), aid) | 56 ctx := UseWithAppID(context.Background(), aid) |
57 » ctx, err := info.Get(ctx).Namespace(ns) | 57 » if ns != "" { |
58 » if err != nil { | 58 » » var err error |
59 » » return nil, err | 59 » » if ctx, err = info.Get(ctx).Namespace(ns); err != nil { |
| 60 » » » return nil, err |
| 61 » » } |
60 } | 62 } |
| 63 |
61 ret := ds.Get(ctx) | 64 ret := ds.Get(ctx) |
62 t := ret.Testable() | 65 t := ret.Testable() |
63 t.AutoIndex(true) | 66 t.AutoIndex(true) |
64 t.Consistent(true) | 67 t.Consistent(true) |
65 t.DisableSpecialEntities(true) | 68 t.DisableSpecialEntities(true) |
66 return ret, nil | 69 return ret, nil |
67 } | 70 } |
68 | 71 |
69 //////////////////////////////////// dsImpl //////////////////////////////////// | 72 //////////////////////////////////// dsImpl //////////////////////////////////// |
70 | 73 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 return countQuery(fq, d.data.parent.aid, d.ns, true, d.data.snap, d.data
.snap) | 221 return countQuery(fq, d.data.parent.aid, d.ns, true, d.data.snap, d.data
.snap) |
219 } | 222 } |
220 | 223 |
221 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio
nOptions) error { | 224 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio
nOptions) error { |
222 return errors.New("datastore: nested transactions are not supported") | 225 return errors.New("datastore: nested transactions are not supported") |
223 } | 226 } |
224 | 227 |
225 func (*txnDsImpl) Testable() ds.Testable { | 228 func (*txnDsImpl) Testable() ds.Testable { |
226 return nil | 229 return nil |
227 } | 230 } |
OLD | NEW |