Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ds-leveldb
Commits
4c06c490
Unverified
Commit
4c06c490
authored
Jan 24, 2019
by
Steven Allen
Committed by
GitHub
Jan 24, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #20 from ipfs/feat/expose-type
Expose Datastore type
parents
f602d2cd
a0e5a05f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
15 deletions
+15
-15
datastore.go
datastore.go
+10
-10
ds_test.go
ds_test.go
+5
-5
No files found.
datastore.go
View file @
4c06c490
...
...
@@ -15,14 +15,14 @@ import (
"github.com/syndtr/goleveldb/leveldb/util"
)
type
d
atastore
struct
{
type
D
atastore
struct
{
*
accessor
DB
*
leveldb
.
DB
path
string
}
var
_
ds
.
Datastore
=
(
*
d
atastore
)(
nil
)
var
_
ds
.
TxnDatastore
=
(
*
d
atastore
)(
nil
)
var
_
ds
.
Datastore
=
(
*
D
atastore
)(
nil
)
var
_
ds
.
TxnDatastore
=
(
*
D
atastore
)(
nil
)
// Options is an alias of syndtr/goleveldb/opt.Options which might be extended
// in the future.
...
...
@@ -31,7 +31,7 @@ type Options opt.Options
// NewDatastore returns a new datastore backed by leveldb
//
// for path == "", an in memory bachend will be chosen
func
NewDatastore
(
path
string
,
opts
*
Options
)
(
*
d
atastore
,
error
)
{
func
NewDatastore
(
path
string
,
opts
*
Options
)
(
*
D
atastore
,
error
)
{
var
nopts
opt
.
Options
if
opts
!=
nil
{
nopts
=
opt
.
Options
(
*
opts
)
...
...
@@ -53,7 +53,7 @@ func NewDatastore(path string, opts *Options) (*datastore, error) {
return
nil
,
err
}
return
&
d
atastore
{
return
&
D
atastore
{
accessor
:
&
accessor
{
ldb
:
db
},
DB
:
db
,
path
:
path
,
...
...
@@ -233,7 +233,7 @@ func (a *accessor) runQuery(worker goprocess.Process, qrb *dsq.ResultBuilder) {
// DiskUsage returns the current disk size used by this levelDB.
// For in-mem datastores, it will return 0.
func
(
d
*
d
atastore
)
DiskUsage
()
(
uint64
,
error
)
{
func
(
d
*
D
atastore
)
DiskUsage
()
(
uint64
,
error
)
{
if
d
.
path
==
""
{
// in-mem
return
0
,
nil
}
...
...
@@ -256,18 +256,18 @@ func (d *datastore) DiskUsage() (uint64, error) {
}
// LevelDB needs to be closed.
func
(
d
*
d
atastore
)
Close
()
(
err
error
)
{
func
(
d
*
D
atastore
)
Close
()
(
err
error
)
{
return
d
.
DB
.
Close
()
}
func
(
d
*
d
atastore
)
IsThreadSafe
()
{}
func
(
d
*
D
atastore
)
IsThreadSafe
()
{}
type
leveldbBatch
struct
{
b
*
leveldb
.
Batch
db
*
leveldb
.
DB
}
func
(
d
*
d
atastore
)
Batch
()
(
ds
.
Batch
,
error
)
{
func
(
d
*
D
atastore
)
Batch
()
(
ds
.
Batch
,
error
)
{
return
&
leveldbBatch
{
b
:
new
(
leveldb
.
Batch
),
db
:
d
.
DB
,
...
...
@@ -302,7 +302,7 @@ func (t *transaction) Discard() {
t
.
tx
.
Discard
()
}
func
(
d
*
d
atastore
)
NewTransaction
(
readOnly
bool
)
(
ds
.
Txn
,
error
)
{
func
(
d
*
D
atastore
)
NewTransaction
(
readOnly
bool
)
(
ds
.
Txn
,
error
)
{
tx
,
err
:=
d
.
DB
.
OpenTransaction
()
if
err
!=
nil
{
return
nil
,
err
...
...
ds_test.go
View file @
4c06c490
...
...
@@ -28,7 +28,7 @@ var testcases = map[string]string{
//
// d, close := newDS(t)
// defer close()
func
newDS
(
t
*
testing
.
T
)
(
*
d
atastore
,
func
())
{
func
newDS
(
t
*
testing
.
T
)
(
*
D
atastore
,
func
())
{
path
,
err
:=
ioutil
.
TempDir
(
"/tmp"
,
"testing_leveldb_"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -45,7 +45,7 @@ func newDS(t *testing.T) (*datastore, func()) {
}
// newDSMem returns an in-memory datastore.
func
newDSMem
(
t
*
testing
.
T
)
*
d
atastore
{
func
newDSMem
(
t
*
testing
.
T
)
*
D
atastore
{
d
,
err
:=
NewDatastore
(
""
,
nil
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -53,7 +53,7 @@ func newDSMem(t *testing.T) *datastore {
return
d
}
func
addTestCases
(
t
*
testing
.
T
,
d
*
d
atastore
,
testcases
map
[
string
]
string
)
{
func
addTestCases
(
t
*
testing
.
T
,
d
*
D
atastore
,
testcases
map
[
string
]
string
)
{
for
k
,
v
:=
range
testcases
{
dsk
:=
ds
.
NewKey
(
k
)
if
err
:=
d
.
Put
(
dsk
,
[]
byte
(
v
));
err
!=
nil
{
...
...
@@ -74,7 +74,7 @@ func addTestCases(t *testing.T, d *datastore, testcases map[string]string) {
}
func
testQuery
(
t
*
testing
.
T
,
d
*
d
atastore
)
{
func
testQuery
(
t
*
testing
.
T
,
d
*
D
atastore
)
{
addTestCases
(
t
,
d
,
testcases
)
rs
,
err
:=
d
.
Query
(
dsq
.
Query
{
Prefix
:
"/a/"
})
...
...
@@ -146,7 +146,7 @@ func expectMatches(t *testing.T, expect []string, actualR dsq.Results) {
}
}
func
testBatching
(
t
*
testing
.
T
,
d
*
d
atastore
)
{
func
testBatching
(
t
*
testing
.
T
,
d
*
D
atastore
)
{
b
,
err
:=
d
.
Batch
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment