Files
dolt/go/datas/factory.go
Ben Kalman fa1ab8a61c Make datas.localFactory public and add NewLocalFactory (#2961)
I want to adapt datas.NewLocalFactory(chunks.NewMemoryStoreFactory()).
2016-12-19 10:46:25 -08:00

35 lines
912 B
Go

// Copyright 2016 Attic Labs, Inc. All rights reserved.
// Licensed under the Apache License, version 2.0:
// http://www.apache.org/licenses/LICENSE-2.0
package datas
import "github.com/attic-labs/noms/go/chunks"
// Factory allows the creation of namespaced Database instances. The details of how namespaces are separated is left up to the particular implementation of Factory and Database.
type Factory interface {
Create(string) (Database, bool)
// Shutter shuts down the factory. Subsequent calls to Create() will fail.
Shutter()
}
type LocalFactory struct {
cf chunks.Factory
}
func NewLocalFactory(cf chunks.Factory) *LocalFactory {
return &LocalFactory{cf}
}
func (lf *LocalFactory) Create(ns string) (Database, bool) {
if cs := lf.cf.CreateStore(ns); cs != nil {
return newLocalDatabase(cs), true
}
return &LocalDatabase{}, false
}
func (lf *LocalFactory) Shutter() {
lf.cf.Shutter()
}