Skip to content

Commit a0e5a05

Browse files
magik6kStebalien
authored andcommitted
Expose Datastore type
1 parent f602d2c commit a0e5a05

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

datastore.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import (
1515
"github.com/syndtr/goleveldb/leveldb/util"
1616
)
1717

18-
type datastore struct {
18+
type Datastore struct {
1919
*accessor
2020
DB *leveldb.DB
2121
path string
2222
}
2323

24-
var _ ds.Datastore = (*datastore)(nil)
25-
var _ ds.TxnDatastore = (*datastore)(nil)
24+
var _ ds.Datastore = (*Datastore)(nil)
25+
var _ ds.TxnDatastore = (*Datastore)(nil)
2626

2727
// Options is an alias of syndtr/goleveldb/opt.Options which might be extended
2828
// in the future.
@@ -31,7 +31,7 @@ type Options opt.Options
3131
// NewDatastore returns a new datastore backed by leveldb
3232
//
3333
// for path == "", an in memory bachend will be chosen
34-
func NewDatastore(path string, opts *Options) (*datastore, error) {
34+
func NewDatastore(path string, opts *Options) (*Datastore, error) {
3535
var nopts opt.Options
3636
if opts != nil {
3737
nopts = opt.Options(*opts)
@@ -53,7 +53,7 @@ func NewDatastore(path string, opts *Options) (*datastore, error) {
5353
return nil, err
5454
}
5555

56-
return &datastore{
56+
return &Datastore{
5757
accessor: &accessor{ldb: db},
5858
DB: db,
5959
path: path,
@@ -233,7 +233,7 @@ func (a *accessor) runQuery(worker goprocess.Process, qrb *dsq.ResultBuilder) {
233233

234234
// DiskUsage returns the current disk size used by this levelDB.
235235
// For in-mem datastores, it will return 0.
236-
func (d *datastore) DiskUsage() (uint64, error) {
236+
func (d *Datastore) DiskUsage() (uint64, error) {
237237
if d.path == "" { // in-mem
238238
return 0, nil
239239
}
@@ -256,18 +256,18 @@ func (d *datastore) DiskUsage() (uint64, error) {
256256
}
257257

258258
// LevelDB needs to be closed.
259-
func (d *datastore) Close() (err error) {
259+
func (d *Datastore) Close() (err error) {
260260
return d.DB.Close()
261261
}
262262

263-
func (d *datastore) IsThreadSafe() {}
263+
func (d *Datastore) IsThreadSafe() {}
264264

265265
type leveldbBatch struct {
266266
b *leveldb.Batch
267267
db *leveldb.DB
268268
}
269269

270-
func (d *datastore) Batch() (ds.Batch, error) {
270+
func (d *Datastore) Batch() (ds.Batch, error) {
271271
return &leveldbBatch{
272272
b: new(leveldb.Batch),
273273
db: d.DB,
@@ -302,7 +302,7 @@ func (t *transaction) Discard() {
302302
t.tx.Discard()
303303
}
304304

305-
func (d *datastore) NewTransaction(readOnly bool) (ds.Txn, error) {
305+
func (d *Datastore) NewTransaction(readOnly bool) (ds.Txn, error) {
306306
tx, err := d.DB.OpenTransaction()
307307
if err != nil {
308308
return nil, err

ds_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var testcases = map[string]string{
2828
//
2929
// d, close := newDS(t)
3030
// defer close()
31-
func newDS(t *testing.T) (*datastore, func()) {
31+
func newDS(t *testing.T) (*Datastore, func()) {
3232
path, err := ioutil.TempDir("/tmp", "testing_leveldb_")
3333
if err != nil {
3434
t.Fatal(err)
@@ -45,15 +45,15 @@ func newDS(t *testing.T) (*datastore, func()) {
4545
}
4646

4747
// newDSMem returns an in-memory datastore.
48-
func newDSMem(t *testing.T) *datastore {
48+
func newDSMem(t *testing.T) *Datastore {
4949
d, err := NewDatastore("", nil)
5050
if err != nil {
5151
t.Fatal(err)
5252
}
5353
return d
5454
}
5555

56-
func addTestCases(t *testing.T, d *datastore, testcases map[string]string) {
56+
func addTestCases(t *testing.T, d *Datastore, testcases map[string]string) {
5757
for k, v := range testcases {
5858
dsk := ds.NewKey(k)
5959
if err := d.Put(dsk, []byte(v)); err != nil {
@@ -74,7 +74,7 @@ func addTestCases(t *testing.T, d *datastore, testcases map[string]string) {
7474

7575
}
7676

77-
func testQuery(t *testing.T, d *datastore) {
77+
func testQuery(t *testing.T, d *Datastore) {
7878
addTestCases(t, d, testcases)
7979

8080
rs, err := d.Query(dsq.Query{Prefix: "/a/"})
@@ -146,7 +146,7 @@ func expectMatches(t *testing.T, expect []string, actualR dsq.Results) {
146146
}
147147
}
148148

149-
func testBatching(t *testing.T, d *datastore) {
149+
func testBatching(t *testing.T, d *Datastore) {
150150
b, err := d.Batch()
151151
if err != nil {
152152
t.Fatal(err)

0 commit comments

Comments
 (0)