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-datastore
Commits
f58423f8
Commit
f58423f8
authored
Jan 10, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
namespace: fix query
parent
b15d86ef
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
1 deletion
+42
-1
namespace/namespace.go
namespace/namespace.go
+42
-1
No files found.
namespace/namespace.go
View file @
f58423f8
...
...
@@ -3,9 +3,11 @@ package namespace
import
(
"fmt"
"strings"
"time"
ds
"github.com/jbenet/go-datastore"
ktds
"github.com/jbenet/go-datastore/keytransform"
dsq
"github.com/jbenet/go-datastore/query"
)
// PrefixTransform constructs a KeyTransform with a pair of functions that
...
...
@@ -40,5 +42,44 @@ func Wrap(child ds.Datastore, prefix ds.Key) ktds.Datastore {
panic
(
"child (ds.Datastore) is nil"
)
}
return
ktds
.
Wrap
(
child
,
PrefixTransform
(
prefix
))
d
:=
ktds
.
Wrap
(
child
,
PrefixTransform
(
prefix
))
return
&
datastore
{
Datastore
:
d
,
raw
:
child
,
prefix
:
prefix
}
}
type
datastore
struct
{
prefix
ds
.
Key
raw
ds
.
Datastore
ktds
.
Datastore
}
// Query implements Query, inverting keys on the way back out.
func
(
d
*
datastore
)
Query
(
q
dsq
.
Query
)
(
dsq
.
Results
,
error
)
{
qr
,
err
:=
d
.
raw
.
Query
(
q
)
if
err
!=
nil
{
return
nil
,
err
}
ch
:=
make
(
chan
dsq
.
Result
)
go
func
()
{
defer
close
(
ch
)
defer
qr
.
Close
()
for
r
:=
range
qr
.
Next
()
{
if
r
.
Error
!=
nil
{
ch
<-
r
continue
}
k
:=
ds
.
NewKey
(
r
.
Entry
.
Key
)
if
!
d
.
prefix
.
IsAncestorOf
(
k
)
{
continue
}
r
.
Entry
.
Key
=
d
.
Datastore
.
InvertKey
(
k
)
.
String
()
ch
<-
r
<-
time
.
After
(
100
*
time
.
Millisecond
)
}
}()
return
dsq
.
DerivedResults
(
qr
,
ch
),
nil
}
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