mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-30 11:31:37 -05:00
8134433126
There was no way to create a datas.Factory from outside the datas package except via datas.Flags. Also, this patch moves the CreateFactory() method on Flags into the file where all the rest of the Flags stuff is defined.
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package datas
|
|
|
|
import "github.com/attic-labs/noms/chunks"
|
|
|
|
// Factory allows the creation of namespaced DataStore instances. The details of how namespaces are separated is left up to the particular implementation of Factory and DataStore.
|
|
type Factory interface {
|
|
Create(string) (DataStore, bool)
|
|
|
|
// Shutter shuts down the factory. Subsequent calls to Create() will fail.
|
|
Shutter()
|
|
}
|
|
|
|
type localFactory struct {
|
|
cf chunks.Factory
|
|
}
|
|
|
|
func (lf *localFactory) Create(ns string) (DataStore, bool) {
|
|
if cs := lf.cf.CreateStore(ns); cs != nil {
|
|
return newLocalDataStore(cs), true
|
|
}
|
|
return &LocalDataStore{}, false
|
|
}
|
|
|
|
func (lf *localFactory) Shutter() {
|
|
lf.cf.Shutter()
|
|
}
|
|
|
|
type remoteFactory struct {
|
|
cf chunks.Factory
|
|
}
|
|
|
|
func (rf *remoteFactory) Create(ns string) (DataStore, bool) {
|
|
if cs := rf.cf.CreateStore(ns); cs != nil {
|
|
return newRemoteDataStore(cs), true
|
|
}
|
|
return &LocalDataStore{}, false
|
|
}
|
|
|
|
func (rf *remoteFactory) Shutter() {
|
|
rf.cf.Shutter()
|
|
}
|
|
|
|
func NewTestFactory(cf chunks.Factory) Factory {
|
|
return &localFactory{cf}
|
|
}
|