store

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INDEX_SUBLEVEL_NAME = "index"
	DELIMITER           = "\x00"
	NEGATIVE_PREFIX     = "!"
	NEGATIVE_OFFSET     = int64(^uint64(0) >> 1)
	MAX_INT_STRING_LEN  = 19 // Length of string representation of max int64
)
View Source
const (
	SortDirectionAscending  = "ascending"
	SortDirectionDescending = "descending"
)

Variables

View Source
var PlaceholderValue = []byte{0}

PlaceholderValue is used as a placeholder value for reference counting

Functions

This section is empty.

Types

type AssociateGormResult added in v0.1.6

type AssociateGormResult struct {
	DataCid  string
	DataSize int64
}

type BlockstoreLevel

type BlockstoreLevel struct {
	// contains filtered or unexported fields
}

BlockstoreLevel implements the Blockstore interface using LevelDB

func NewBlockstoreLevel

func NewBlockstoreLevel(path string) (*BlockstoreLevel, error)

NewBlockstoreLevel creates a new BlockstoreLevel

func (*BlockstoreLevel) AllKeysChan

func (b *BlockstoreLevel) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error)

AllKeysChan returns a channel of all CIDs in the database

func (*BlockstoreLevel) Clear

func (b *BlockstoreLevel) Clear() error

Clear deletes all entries in the database

func (*BlockstoreLevel) Close

func (b *BlockstoreLevel) Close() error

Close closes the database

func (*BlockstoreLevel) Delete

func (b *BlockstoreLevel) Delete(ctx context.Context, c cid.Cid) error

Delete removes a block from the database

func (*BlockstoreLevel) Get

func (b *BlockstoreLevel) Get(ctx context.Context, c cid.Cid) ([]byte, error)

Get retrieves a block from the database

func (*BlockstoreLevel) Has

func (b *BlockstoreLevel) Has(ctx context.Context, c cid.Cid) (bool, error)

Has checks if a block exists in the database

func (*BlockstoreLevel) IsEmpty

func (b *BlockstoreLevel) IsEmpty() (bool, error)

IsEmpty checks if the database is empty

func (*BlockstoreLevel) Open

func (b *BlockstoreLevel) Open() error

Open opens the database

func (*BlockstoreLevel) Partition

func (b *BlockstoreLevel) Partition(tenant string) (*BlockstoreLevel, error)

Add a Partition method to BlockstoreLevel

func (*BlockstoreLevel) Put

func (b *BlockstoreLevel) Put(ctx context.Context, c cid.Cid, block []byte) error

Put stores a block in the database

func (*BlockstoreLevel) PutMany

func (b *BlockstoreLevel) PutMany(ctx context.Context, blocks map[cid.Cid][]byte) error

PutMany stores multiple blocks in the database

type DataFilter added in v0.1.6

type DataFilter struct {
	Property string
	Operator string
	Value    interface{}
}

type DataStoreLevel

type DataStoreLevel struct {
	// contains filtered or unexported fields
}

DataStoreLevel is a simple implementation of DataStore that works in both the browser and server-side. Leverages LevelDB under the hood.

It has the following structure (`+` represents a sublevel and `->` represents a key->value pair):

'data' + <tenant> + <dataCid> -> <data>
'references' + <tenant> + <dataCid> + <messageCid> -> PlaceholderValue

This allows for the <data> to be shared for everything that uses the same <dataCid> while also making sure that the <data> can only be deleted if there are no <messageCid> for any <tenant> still using it.

func NewDataStoreLevel

func NewDataStoreLevel(config DataStoreLevelConfig) (*DataStoreLevel, error)

NewDataStoreLevel creates a new instance of DataStoreLevel

func (*DataStoreLevel) Clear

func (d *DataStoreLevel) Clear(ctx context.Context) error

Clear deletes everything in the store

func (*DataStoreLevel) Close

func (d *DataStoreLevel) Close() error

Close closes the datastore

func (*DataStoreLevel) Delete

func (d *DataStoreLevel) Delete(ctx context.Context, tenant, messageCid, dataCid string) error

Delete removes the reference and deletes data if it's no longer referenced

func (*DataStoreLevel) Get

func (d *DataStoreLevel) Get(ctx context.Context, tenant, messageCid, dataCid string) (*GetResult, error)

Get retrieves the data if the caller has access

func (*DataStoreLevel) Open

func (d *DataStoreLevel) Open() error

Open opens the datastore (no-op for LevelDB)

func (*DataStoreLevel) Put

func (d *DataStoreLevel) Put(ctx context.Context, tenant, messageCid, dataCid string, dataReader io.Reader) (*PutResult, error)

Put stores the data and updates reference counting

type DataStoreLevelConfig

type DataStoreLevelConfig struct {
	BlockstoreLocation string
}

DataStoreLevelConfig holds configuration options for DataStoreLevel

type DataStoreSQL added in v0.1.6

type DataStoreSQL struct {
	// contains filtered or unexported fields
}

func NewDataStoreSQL added in v0.1.6

func NewDataStoreSQL(config MessageStoreSQLConfig) (*DataStoreSQL, error)

func (*DataStoreSQL) Associate added in v0.1.6

func (dss *DataStoreSQL) Associate(tenant string, messageCid string, dataCid string) (*AssociateGormResult, error)

func (*DataStoreSQL) Clear added in v0.1.6

func (dss *DataStoreSQL) Clear() error

func (*DataStoreSQL) Close added in v0.1.6

func (dss *DataStoreSQL) Close() error

func (*DataStoreSQL) Delete added in v0.1.6

func (dss *DataStoreSQL) Delete(tenant string, messageCid string, dataCid string) error

func (*DataStoreSQL) Get added in v0.1.6

func (dss *DataStoreSQL) Get(tenant string, messageCid string, dataCid string) (string, int64, io.Reader, error)

func (*DataStoreSQL) Open added in v0.1.6

func (dss *DataStoreSQL) Open() error

func (*DataStoreSQL) Put added in v0.1.6

func (dss *DataStoreSQL) Put(tenant string, messageCid string, dataCid string,
	dataStream io.Reader) (*PutGormResult, error)

type EqualFilter

type EqualFilter interface{}

type EventLogSQL added in v0.1.6

type EventLogSQL struct {
	// contains filtered or unexported fields
}

func NewEventLogSQL added in v0.1.6

func NewEventLogSQL(config MessageStoreSQLConfig) (*EventLogSQL, error)

func (*EventLogSQL) Append added in v0.1.6

func (els *EventLogSQL) Append(tenant string, messageCid string, indexes KeyValues) error

func (*EventLogSQL) Clear added in v0.1.6

func (els *EventLogSQL) Clear() error

func (*EventLogSQL) Close added in v0.1.6

func (els *EventLogSQL) Close() error

func (*EventLogSQL) DeleteEventsByCid added in v0.1.6

func (els *EventLogSQL) DeleteEventsByCid(tenant string, messageCids []string) error

func (*EventLogSQL) GetEvents added in v0.1.6

func (els *EventLogSQL) GetEvents(tenant string, options *EventOptions) ([]string, error)

func (*EventLogSQL) Open added in v0.1.6

func (els *EventLogSQL) Open() error

func (*EventLogSQL) QueryEvents added in v0.1.6

func (els *EventLogSQL) QueryEvents(tenant string, filters []DataFilter, options *EventOptions) ([]string, error)

type EventOptions added in v0.1.6

type EventOptions struct {
	Cursor string
}

type Filter

type Filter = map[string]interface{}

type GenericMessage

type GenericMessage interface{}

type GetGormResult added in v0.1.6

type GetGormResult struct {
	DataCid    string
	DataSize   int64
	DataStream io.Reader
}

type GetResult

type GetResult struct {
	DataCid    string
	DataSize   uint64
	DataReader io.ReadCloser
}

GetResult is the result of a Get operation

type GormMessageStore added in v0.1.6

type GormMessageStore struct {
	// contains filtered or unexported fields
}

func NewMessageStoreSQL added in v0.1.6

func NewMessageStoreSQL(config MessageStoreSQLConfig) (*GormMessageStore, error)

func (*GormMessageStore) Clear added in v0.1.6

func (mss *GormMessageStore) Clear() error

func (*GormMessageStore) Close added in v0.1.6

func (mss *GormMessageStore) Close() error

func (*GormMessageStore) Delete added in v0.1.6

func (mss *GormMessageStore) Delete(tenant string, cidString string, options *MessageStoreOptions) error

func (*GormMessageStore) Get added in v0.1.6

func (mss *GormMessageStore) Get(tenant string, messageCid string) (interface{}, error)

func (*GormMessageStore) Open added in v0.1.6

func (mss *GormMessageStore) Open() error

func (*GormMessageStore) Put added in v0.1.6

func (mss *GormMessageStore) Put(tenant string, message GenericMessage, indexes KeyValues, options *MessageStoreOptions) error

func (*GormMessageStore) Query added in v0.1.6

func (mss *GormMessageStore) Query(tenant string, filters []DataFilter, messageSort *MessageSort, pagination *Pagination, options *MessageStoreOptions) ([]GenericMessage, string, error)

type IndexLevel

type IndexLevel struct {
	// contains filtered or unexported fields
}

func NewIndexLevel

func NewIndexLevel(config IndexLevelConfig) (*IndexLevel, error)

func (*IndexLevel) Clear

func (il *IndexLevel) Clear() error

func (*IndexLevel) Close

func (il *IndexLevel) Close() error

func (*IndexLevel) Delete

func (il *IndexLevel) Delete(tenant string, itemId string, options *IndexLevelOptions) error

func (*IndexLevel) Put

func (il *IndexLevel) Put(tenant string, itemId string, indexes KeyValues, options *IndexLevelOptions) error

func (*IndexLevel) Query

func (il *IndexLevel) Query(tenant string, filters []Filter, queryOptions QueryOptions, options *IndexLevelOptions) ([]string, error)

type IndexLevelConfig

type IndexLevelConfig struct {
	Location string
}

type IndexLevelOptions

type IndexLevelOptions struct {
	Context context.Context
}

type IndexedItem

type IndexedItem struct {
	ItemID  string    `json:"itemId"`
	Indexes KeyValues `json:"indexes"`
}

type KeyValues

type KeyValues map[string]interface{}

type LevelWrapper

type LevelWrapper struct {
	// contains filtered or unexported fields
}

LevelWrapper provides a wrapper around LevelDB with partitioning support.

func NewLevelWrapper

func NewLevelWrapper(config LevelWrapperConfig) *LevelWrapper

NewLevelWrapper creates a new LevelWrapper instance.

func (*LevelWrapper) Batch

func (lw *LevelWrapper) Batch(operations []LevelWrapperBatchOperation, options *LevelWrapperOptions) error

Batch executes a batch of operations.

func (*LevelWrapper) Clear

func (lw *LevelWrapper) Clear() error

Clear removes all entries from the database.

func (*LevelWrapper) Close

func (lw *LevelWrapper) Close() error

Close closes the LevelDB database.

func (*LevelWrapper) Delete

func (lw *LevelWrapper) Delete(key string, options *LevelWrapperOptions) error

Delete removes a key-value pair.

func (*LevelWrapper) Get

func (lw *LevelWrapper) Get(key string, options *LevelWrapperOptions) ([]byte, error)

Get retrieves a value by key.

func (*LevelWrapper) Has

func (lw *LevelWrapper) Has(key string, options *LevelWrapperOptions) (bool, error)

Has checks if a key exists.

func (*LevelWrapper) IsEmpty

func (lw *LevelWrapper) IsEmpty(options *LevelWrapperOptions) (bool, error)

IsEmpty checks if the database is empty.

func (*LevelWrapper) Iterator

func (lw *LevelWrapper) Iterator(iterOptions *LevelWrapperIteratorOptions, options *LevelWrapperOptions) (iterator.Iterator, error)

Iterator returns an iterator over key-value pairs with options.

func (*LevelWrapper) Keys

func (lw *LevelWrapper) Keys(options *LevelWrapperOptions) (iterator.Iterator, error)

Keys returns an iterator over the keys.

func (*LevelWrapper) Open

func (lw *LevelWrapper) Open() error

Open opens the LevelDB database.

func (*LevelWrapper) Partition

func (lw *LevelWrapper) Partition(name string) (*LevelWrapper, error)

Partition creates a new LevelWrapper for a sublevel (partition).

func (*LevelWrapper) Put

func (lw *LevelWrapper) Put(key string, value []byte, options *LevelWrapperOptions) error

Put stores a key-value pair.

type LevelWrapperBatchOperation

type LevelWrapperBatchOperation struct {
	Type  string
	Key   []byte
	Value []byte
}

LevelWrapperBatchOperation represents a batch operation.

type LevelWrapperConfig

type LevelWrapperConfig struct {
	Location    string
	OpenOptions *opt.Options
}

LevelWrapperConfig holds configuration for LevelWrapper.

type LevelWrapperIteratorOptions

type LevelWrapperIteratorOptions struct {
	Start   []byte
	Limit   []byte
	Reverse bool
}

LevelWrapperIteratorOptions represents options for iterators.

type LevelWrapperOptions

type LevelWrapperOptions struct {
	Context context.Context
}

LevelWrapperOptions represents options for LevelWrapper methods.

type MessageSort

type MessageSort struct {
	DateCreated      *SortDirection
	DatePublished    *SortDirection
	MessageTimestamp *SortDirection
	Property         string // The property/column to sort by
	Direction        string // The sort direction ("ASC" or "DESC")

}

MessageSort specifies sorting options for messages

type MessageStoreLevel

type MessageStoreLevel struct {
	// contains filtered or unexported fields
}

MessageStoreLevel represents a message store using LevelDB

func NewMessageStoreLevel

func NewMessageStoreLevel(config MessageStoreLevelConfig) (*MessageStoreLevel, error)

NewMessageStoreLevel creates a new MessageStoreLevel instance

func (*MessageStoreLevel) Clear

func (msl *MessageStoreLevel) Clear() error

Clear removes all messages from the store

func (*MessageStoreLevel) Close

func (msl *MessageStoreLevel) Close() error

Close closes the message store

func (*MessageStoreLevel) Delete

func (msl *MessageStoreLevel) Delete(tenant, cidString string, options *MessageStoreOptions) error

Delete removes a message from the store

func (*MessageStoreLevel) Get

func (msl *MessageStoreLevel) Get(tenant, cidString string, options *MessageStoreOptions) (GenericMessage, error)

Get retrieves a message by its CID

func (*MessageStoreLevel) Open

func (msl *MessageStoreLevel) Open() error

Open opens the message store

func (*MessageStoreLevel) Put

func (msl *MessageStoreLevel) Put(tenant string, message GenericMessage, indexes KeyValues, options *MessageStoreOptions) error

Put stores a new message in the store

func (*MessageStoreLevel) Query

func (msl *MessageStoreLevel) Query(tenant string, filters []Filter, messageSort *MessageSort, pagination *Pagination, options *MessageStoreOptions) ([]GenericMessage, string, error)

Query retrieves messages based on filters and sorting options

type MessageStoreLevelConfig

type MessageStoreLevelConfig struct {
	BlockstoreLocation  string
	IndexLocation       string
	CreateLevelDatabase func(string) (*LevelWrapper, error)
}

MessageStoreLevelConfig holds configuration for MessageStoreLevel

type MessageStoreOptions

type MessageStoreOptions struct {
	Signal context.Context
}

MessageStoreOptions contains options for message store operations

type MessageStoreSQL added in v0.1.6

type MessageStoreSQL struct {
	// contains filtered or unexported fields
}

MessageStoreSQL represents a message store using SQL database

type MessageStoreSQLConfig added in v0.1.6

type MessageStoreSQLConfig struct {
	DBConfig config.DBConfig
}

MessageStoreSQLConfig holds configuration for MessageStoreSQL

type Pagination

type Pagination struct {
	Limit  int
	Cursor string
}

Pagination specifies pagination options

type PutGormResult added in v0.1.6

type PutGormResult struct {
	DataCid  string
	DataSize int64
}

type PutResult

type PutResult struct {
	DataCid  string
	DataSize uint64
}

PutResult is the result of a Put operation

type QueryOptions

type QueryOptions struct {
	Limit         int
	Cursor        string
	SortProperty  string
	SortDirection string
}

type RangeFilter

type RangeFilter map[string]interface{}

type SortDirection

type SortDirection string

SortDirection represents the direction of sorting

const (
	SortAscending  SortDirection = "asc"
	SortDescending SortDirection = "desc"
)

Sort direction constants

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL