mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-03 03:10:26 -05:00
4be8107405
In service of streaming set and map mutators, it'd be helpful for ValueStore to implement some methods that are exposed only to other code within the types package, even when a ValueStore is embedded in a Database. That said, we don't want those methods to become a part of the public Database API. To enable this, this patch changes databaseCommon to embed a *types.ValueStore, instead of composing one. This causes all the ValueStore methods to be a part of the databaseCommon API, but since all the Database construction methods return a Database by interface, stuff like BatchStore() all gets masked. Thus, callers still can't access ValueStore methods. Databases are passed into the types package as ValueReadWriters, though, so code in there can call any method on that interface -- including unexported stuff.
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
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/d"
|
|
"github.com/attic-labs/noms/go/types"
|
|
"github.com/julienschmidt/httprouter"
|
|
)
|
|
|
|
// Database provides versioned storage for noms values. Each Database instance represents one moment in history. Heads() returns the Commit from each active fork at that moment. The Commit() method returns a new Database, representing a new moment in history.
|
|
type RemoteDatabaseClient struct {
|
|
databaseCommon
|
|
}
|
|
|
|
func NewRemoteDatabase(baseURL, auth string) *RemoteDatabaseClient {
|
|
httpBS := newHTTPBatchStore(baseURL, auth)
|
|
return &RemoteDatabaseClient{newDatabaseCommon(newCachingChunkHaver(httpBS), types.NewValueStore(httpBS), httpBS)}
|
|
}
|
|
|
|
func (rds *RemoteDatabaseClient) validatingBatchStore() (bs types.BatchStore) {
|
|
bs = rds.ValueStore.BatchStore()
|
|
d.Chk.True(bs.IsValidating())
|
|
return
|
|
}
|
|
|
|
func (rds *RemoteDatabaseClient) Commit(datasetID string, commit types.Struct) (Database, error) {
|
|
err := rds.doCommit(datasetID, commit)
|
|
return &RemoteDatabaseClient{newDatabaseCommon(rds.cch, rds.ValueStore, rds.rt)}, err
|
|
}
|
|
|
|
func (rds *RemoteDatabaseClient) Delete(datasetID string) (Database, error) {
|
|
err := rds.doDelete(datasetID)
|
|
return &RemoteDatabaseClient{newDatabaseCommon(rds.cch, rds.ValueStore, rds.rt)}, err
|
|
}
|
|
|
|
func (rds *RemoteDatabaseClient) SetHead(datasetID string, commit types.Struct) (Database, error) {
|
|
err := rds.doSetHead(datasetID, commit)
|
|
return &RemoteDatabaseClient{newDatabaseCommon(rds.cch, rds.ValueStore, rds.rt)}, err
|
|
}
|
|
|
|
func (f RemoteStoreFactory) CreateStore(ns string) Database {
|
|
return NewRemoteDatabase(f.host+httprouter.CleanPath(ns), f.auth)
|
|
}
|
|
|
|
func (f RemoteStoreFactory) Create(ns string) (Database, bool) {
|
|
if ds := f.CreateStore(ns); ds != nil {
|
|
return ds, true
|
|
}
|
|
return &LocalDatabase{}, false
|
|
}
|
|
|
|
func (f RemoteStoreFactory) Shutter() {}
|
|
|
|
func NewRemoteStoreFactory(host, auth string) Factory {
|
|
return RemoteStoreFactory{host: host, auth: auth}
|
|
}
|
|
|
|
type RemoteStoreFactory struct {
|
|
host string
|
|
auth string
|
|
}
|