Skip to content

Commit

Permalink
feat(docstore): added PutAll/PutBatch + style
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Louvigny <glouvigny@users.noreply.github.com>
  • Loading branch information
glouvigny committed Aug 20, 2021
1 parent 2880e8a commit fbb5d00
Show file tree
Hide file tree
Showing 8 changed files with 482 additions and 181 deletions.
21 changes: 11 additions & 10 deletions baseorbitdb/orbitdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,16 +754,17 @@ func (o *orbitDB) createStore(ctx context.Context, storeType string, parsedDBAdd
}

store, err := storeFunc(ctx, o.IPFS(), identity, parsedDBAddress, &iface.NewStoreOptions{
AccessController: accessController,
Cache: options.Cache,
Replicate: options.Replicate,
Directory: *options.Directory,
SortFn: options.SortFn,
CacheDestroy: func() error { return o.cache.Destroy(o.directory, parsedDBAddress) },
Logger: o.logger,
Tracer: o.tracer,
IO: options.IO,
SharedKey: options.SharedKey,
AccessController: accessController,
Cache: options.Cache,
Replicate: options.Replicate,
Directory: *options.Directory,
SortFn: options.SortFn,
CacheDestroy: func() error { return o.cache.Destroy(o.directory, parsedDBAddress) },
Logger: o.logger,
Tracer: o.tracer,
IO: options.IO,
SharedKey: options.SharedKey,
StoreSpecificOpts: options.StoreSpecificOpts,
})
if err != nil {
return nil, errors.Wrap(err, "unable to instantiate store")
Expand Down
38 changes: 29 additions & 9 deletions iface/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ type CreateDBOptions struct {
SortFn ipfslog.SortFn
IO ipfslog.IO
SharedKey enc.SharedKey
StoreSpecificOpts interface{}
}

type CreateDocumentDBOptions struct {
KeyExtractor func(interface{}) (string, error)
Marshal func(interface{}) ([]byte, error)
Unmarshal func(data []byte, v interface{}) error
ItemFactory func() interface{}
}

// DetermineAddressOptions Lists the arguments used to determine a store address
Expand Down Expand Up @@ -70,7 +78,7 @@ type BaseOrbitDB interface {
// RegisterStoreType Registers a new store type
RegisterStoreType(storeType string, constructor StoreConstructor)

// RegisterStoreType Removes a store type
// UnregisterStoreType Removes a store type
UnregisterStoreType(storeType string)

// RegisterAccessControllerType Registers a new access controller type
Expand Down Expand Up @@ -107,7 +115,7 @@ type OrbitDBKVStore interface {
OrbitDBKVStoreProvider
}

// OrbitDBLogStoreProvider Exposes a method providing a key value store
// OrbitDBKVStoreProvider Exposes a method providing a key value store
type OrbitDBKVStoreProvider interface {
// KeyValue Creates or opens an KeyValueStore
KeyValue(ctx context.Context, address string, options *CreateDBOptions) (KeyValueStore, error)
Expand Down Expand Up @@ -165,7 +173,7 @@ type Store interface {
// Replicator Returns the Replicator object
Replicator() replicator.Replicator

// Replicator Returns the Cache object
// Cache Returns the Cache object
Cache() datastore.Datastore

// Drop Removes all the local store content
Expand Down Expand Up @@ -246,18 +254,29 @@ type KeyValueStore interface {
Get(ctx context.Context, key string) ([]byte, error)
}

type DocumentStoreGetOptions struct {
CaseInsensitive bool
PartialMatches bool
}

// DocumentStore A type of store that provides a document store
type DocumentStore interface {
Store

// Put Stores the document
Put(ctx context.Context, document map[string]interface{}) (operation.Operation, error)
Put(ctx context.Context, document interface{}) (operation.Operation, error)

// Delete Clears the document for a key
Delete(ctx context.Context, key string) (operation.Operation, error)

// PutBatch Add values as multiple operations and returns the latest
PutBatch(ctx context.Context, values []interface{}) (operation.Operation, error)

// PutAll Add values as a single operation and returns it
PutAll(ctx context.Context, values []interface{}) (operation.Operation, error)

// Get Retrieves the document for a key
Get(ctx context.Context, key string, caseSensitive bool) ([]map[string]interface{}, error)
Get(ctx context.Context, key string, opts *DocumentStoreGetOptions) ([]interface{}, error)
}

// StoreIndex Index contains the state of a datastore,
Expand Down Expand Up @@ -299,6 +318,7 @@ type NewStoreOptions struct {
Tracer trace.Tracer
IO ipfslog.IO
SharedKey enc.SharedKey
StoreSpecificOpts interface{}
}

type DirectChannelOptions struct {
Expand All @@ -311,7 +331,7 @@ type DirectChannel interface {
// Connect Waits for the other peer to be connected
Connect(context.Context) error

// Sends Sends a message to the other peer
// Send Sends a message to the other peer
Send(context.Context, []byte) error

// Close Closes the connection
Expand Down Expand Up @@ -343,15 +363,15 @@ type PubSubTopic interface {
// WatchPeers subscribes to peers joining or leaving the topic
WatchPeers(ctx context.Context) (<-chan events.Event, error)

// WatchMessages
// WatchMessages Subscribes to new messages
WatchMessages(ctx context.Context) (<-chan *EventPubSubMessage, error)

// Returns the topic name
// Topic Returns the topic name
Topic() string
}

type PubSubInterface interface {
// Subscribe Subscribes to a topic
// TopicSubscribe Subscribes to a topic
TopicSubscribe(ctx context.Context, topic string) (PubSubTopic, error)
}

Expand Down
8 changes: 6 additions & 2 deletions orbitdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package orbitdb
import (
"context"

coreapi "github.com/ipfs/interface-go-ipfs-core"
"github.com/pkg/errors"

"berty.tech/go-orbit-db/accesscontroller/ipfs"
"berty.tech/go-orbit-db/accesscontroller/orbitdb"
"berty.tech/go-orbit-db/accesscontroller/simple"
Expand All @@ -11,8 +14,6 @@ import (
"berty.tech/go-orbit-db/stores/documentstore"
"berty.tech/go-orbit-db/stores/eventlogstore"
"berty.tech/go-orbit-db/stores/kvstore"
coreapi "github.com/ipfs/interface-go-ipfs-core"
"github.com/pkg/errors"
)

type orbitDB struct {
Expand Down Expand Up @@ -52,6 +53,9 @@ type StreamOptions = iface.StreamOptions
// CreateDBOptions An alias of the type defined in the iface package
type CreateDBOptions = iface.CreateDBOptions

// CreateDocumentDBOptions An alias of the type defined in the iface package
type CreateDocumentDBOptions = iface.CreateDocumentDBOptions

// DetermineAddressOptions An alias of the type defined in the iface package
type DetermineAddressOptions = iface.DetermineAddressOptions

Expand Down
Loading

0 comments on commit fbb5d00

Please sign in to comment.