Create metadata db object

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2017-09-22 10:05:35 -07:00
parent acba0f50ef
commit 56c1b79a4c
14 changed files with 56 additions and 30 deletions

View File

@@ -19,7 +19,7 @@ func WithTransactionContext(ctx context.Context, tx *bolt.Tx) context.Context {
// view gets a bolt db transaction either from the context
// or starts a new one with the provided bolt database.
func view(ctx context.Context, db *bolt.DB, fn func(*bolt.Tx) error) error {
func view(ctx context.Context, db *DB, fn func(*bolt.Tx) error) error {
tx, ok := ctx.Value(transactionKey{}).(*bolt.Tx)
if !ok {
return db.View(fn)
@@ -29,7 +29,7 @@ func view(ctx context.Context, db *bolt.DB, fn func(*bolt.Tx) error) error {
// update gets a writable bolt db transaction either from the context
// or starts a new one with the provided bolt database.
func update(ctx context.Context, db *bolt.DB, fn func(*bolt.Tx) error) error {
func update(ctx context.Context, db *DB, fn func(*bolt.Tx) error) error {
tx, ok := ctx.Value(transactionKey{}).(*bolt.Tx)
if !ok {
return db.Update(fn)

View File

@@ -19,12 +19,12 @@ import (
type contentStore struct {
content.Store
db *bolt.DB
db *DB
}
// NewContentStore returns a namespaced content store using an existing
// content store interface.
func NewContentStore(db *bolt.DB, cs content.Store) content.Store {
func NewContentStore(db *DB, cs content.Store) content.Store {
return &contentStore{
Store: cs,
db: db,
@@ -353,7 +353,7 @@ type namespacedWriter struct {
content.Writer
ref string
namespace string
db *bolt.DB
db *DB
}
func (nw *namespacedWriter) Commit(ctx context.Context, size int64, expected digest.Digest, opts ...content.Opt) error {

21
metadata/db.go Normal file
View File

@@ -0,0 +1,21 @@
package metadata
import "github.com/boltdb/bolt"
type DB struct {
db *bolt.DB
}
func NewDB(db *bolt.DB) *DB {
return &DB{
db: db,
}
}
func (m *DB) View(fn func(*bolt.Tx) error) error {
return m.db.View(fn)
}
func (m *DB) Update(fn func(*bolt.Tx) error) error {
return m.db.Update(fn)
}

View File

@@ -19,12 +19,12 @@ import (
type snapshotter struct {
snapshot.Snapshotter
name string
db *bolt.DB
db *DB
}
// NewSnapshotter returns a new Snapshotter which namespaces the given snapshot
// using the provided name and metadata store.
func NewSnapshotter(db *bolt.DB, name string, sn snapshot.Snapshotter) snapshot.Snapshotter {
func NewSnapshotter(db *DB, name string, sn snapshot.Snapshotter) snapshot.Snapshotter {
return &snapshotter{
Snapshotter: sn,
name: name,