Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
d30d7800
Commit
d30d7800
authored
Jan 11, 2017
by
Nick Johnson
Committed by
Felix Lange
Jan 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ethdb: Implement interface for prefixed operations to the DB (#3536)
parent
8820d970
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
database.go
ethdb/database.go
+52
-0
No files found.
ethdb/database.go
View file @
d30d7800
...
@@ -305,3 +305,55 @@ func (b *ldbBatch) Put(key, value []byte) error {
...
@@ -305,3 +305,55 @@ func (b *ldbBatch) Put(key, value []byte) error {
func
(
b
*
ldbBatch
)
Write
()
error
{
func
(
b
*
ldbBatch
)
Write
()
error
{
return
b
.
db
.
Write
(
b
.
b
,
nil
)
return
b
.
db
.
Write
(
b
.
b
,
nil
)
}
}
type
table
struct
{
db
Database
prefix
string
}
// NewTable returns a Database object that prefixes all keys with a given
// string.
func
NewTable
(
db
Database
,
prefix
string
)
Database
{
return
&
table
{
db
:
db
,
prefix
:
prefix
,
}
}
func
(
dt
*
table
)
Put
(
key
[]
byte
,
value
[]
byte
)
error
{
return
dt
.
db
.
Put
(
append
([]
byte
(
dt
.
prefix
),
key
...
),
value
)
}
func
(
dt
*
table
)
Get
(
key
[]
byte
)
([]
byte
,
error
)
{
return
dt
.
db
.
Get
(
append
([]
byte
(
dt
.
prefix
),
key
...
))
}
func
(
dt
*
table
)
Delete
(
key
[]
byte
)
error
{
return
dt
.
db
.
Delete
(
append
([]
byte
(
dt
.
prefix
),
key
...
))
}
func
(
dt
*
table
)
Close
()
{
// Do nothing; don't close the underlying DB.
}
type
tableBatch
struct
{
batch
Batch
prefix
string
}
// NewTableBatch returns a Batch object which prefixes all keys with a given string.
func
NewTableBatch
(
db
Database
,
prefix
string
)
Batch
{
return
&
tableBatch
{
db
.
NewBatch
(),
prefix
}
}
func
(
dt
*
table
)
NewBatch
()
Batch
{
return
&
tableBatch
{
dt
.
db
.
NewBatch
(),
dt
.
prefix
}
}
func
(
tb
*
tableBatch
)
Put
(
key
,
value
[]
byte
)
error
{
return
tb
.
batch
.
Put
(
append
([]
byte
(
tb
.
prefix
),
key
...
),
value
)
}
func
(
tb
*
tableBatch
)
Write
()
error
{
return
tb
.
batch
.
Write
()
}
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