store

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderNone = Order(0)
	OrderAsc  = Order(1)
	OrderDesc = Order(2)
)

Order options.

Variables

View Source
var (
	ErrNotExist = errors.New("not exist")
	ErrExist    = errors.New("exist")
	ErrInvalid  = errors.New("invalid")
)
View Source
var NoLimit = int(0)

NoLimit represents a no limit option.

View Source
var NoOffset = uint(0)

NoOffset represents a no offset option.

Functions

func NewDatabaseExistError added in v0.9.0

func NewDatabaseExistError(name string) error

func NewDatabaseNotExistError

func NewDatabaseNotExistError(name string) error

func NewDatabaseOptionsInvalidError added in v0.9.0

func NewDatabaseOptionsInvalidError(opts any) error

func NewObjectNotExistError

func NewObjectNotExistError(key Key) error

func NewSchemaNotExistError

func NewSchemaNotExistError(name string) error

Types

type Collection added in v0.9.0

type Collection = document.Collection

type Database

type Database interface {
	// Name returns the unique name.
	Name() string
	// Options returns the database options.
	Options() DatabaseOptions
	// Transact begin a new transaction.
	Transact(write bool) (Transaction, error)
}

Database represents a database interface.

type DatabaseOperation

type DatabaseOperation interface {
	// CreateCollection creates a new collection.
	CreateCollection(ctx context.Context, col Collection) error
	// GetCollection returns the specified collection.
	GetCollection(ctx context.Context, name string) (Collection, error)
	// RemoveCollection removes the specified collection.
	RemoveCollection(ctx context.Context, name string) error
	// TruncateCollections removes all collections.
	TruncateCollections(ctx context.Context) error
}

DatabaseOperation represents a database operation.

type DatabaseOptions added in v0.9.0

type DatabaseOptions = map[string]interface{}

DatabaseOptions represents a database options.

type DocumentOperation

type DocumentOperation interface {
	// InsertDocument puts a document object with the specified primary key.
	InsertDocument(ctx context.Context, docKey Key, obj Object) error
	// FindDocuments returns a result set matching the specified key.
	FindDocuments(ctx context.Context, docKey Key, opts ...Option) (ResultSet, error)
	// UpdateDocument updates a document object with the specified primary key.
	UpdateDocument(ctx context.Context, docKey Key, obj Object) error
	// RemoveDocument removes a document object with the specified primary key.
	RemoveDocument(ctx context.Context, docKey Key) error
	// RemoveDocuments removes document objects with the specified primary key.
	RemoveDocuments(ctx context.Context, docKey Key) error
	// TruncateDocuments removes all document objects.
	TruncateDocuments(ctx context.Context) error
}

DocumentOperation represents a document operation.

type IndexOperation

type IndexOperation interface {
	// InsertIndex puts a secondary index with the primary key.
	InsertIndex(ctx context.Context, idxKey Key, key Key) error
	// RemoveIndex removes the specified secondary index.
	RemoveIndex(ctx context.Context, idxKey Key) error
	// FindDocumentsByIndex returns a result set matching the specified index key.
	FindDocumentsByIndex(ctx context.Context, indexKey Key, opts ...Option) (ResultSet, error)
	// TruncateIndexes removes all secondary indexes.
	TruncateIndexes(ctx context.Context) error
}

IndexOperation represents a secondary index operation.

type Key

type Key = document.Key

Key represents an object key.

type LimitOption added in v1.0.0

type LimitOption struct {
	Limit int
}

LimitOption represents a limit option.

func NewLimitOptionWith added in v1.0.0

func NewLimitOptionWith(limit int) *LimitOption

NewLimitOptionWith returns a new limit option.

type Object

type Object = document.Object

Object represents a store object.

type OffsetOption added in v1.0.0

type OffsetOption struct {
	Offset uint
}

OffsetOption represents an offset option.

func NewOffsetOption added in v1.0.0

func NewOffsetOption(offset uint) *OffsetOption

NewLimitOption returns a new offset option.

type Option added in v1.0.0

type Option = any

Option represents a option.

type Order added in v1.0.0

type Order = int

Order represents a order.

type OrderOption added in v1.0.0

type OrderOption struct {
	Order Order
}

OrderOption represents a order option.

func NewOrderOptionWith added in v1.0.0

func NewOrderOptionWith(order Order) *OrderOption

NewOrderOptionWith returns a new order option.

type ResultSet

type ResultSet interface {
	// Next moves the cursor forward next object from its current position.
	Next() bool
	// Object returns an object in the current position.
	Object() Object
	// Object returns all objects in the result set.
	Objects() []Object
}

ResultSet represents a result set which includes query execution results.

type Schema

type Schema = document.Schema

type Store

type Store interface {
	// SetDocumentCoder sets the document coder.
	SetDocumentCoder(coder document.Coder)
	// SetKeyCoder sets the key coder.
	SetKeyCoder(coder document.KeyCoder)
	// CreateDatabase creates a new database.
	CreateDatabase(ctx context.Context, name string) error
	// GetDatabase retruns the specified database.
	GetDatabase(ctx context.Context, name string) (Database, error)
	// RemoveDatabase removes the specified database.
	RemoveDatabase(ctx context.Context, name string) error
	// ListDatabases returns the all databases.
	ListDatabases(ctx context.Context) ([]Database, error)
}

Store represents a store interface.

type Transaction

type Transaction interface {
	TransactionOperation
	// Database returns the transaction database.
	Database() Database
	// Commit commits this transaction.
	Commit(ctx context.Context) error
	// Cancel cancels this transaction.
	Cancel(ctx context.Context) error
}

Transaction represents a transaction interface.

type TransactionOperation

type TransactionOperation interface {
	DatabaseOperation
	DocumentOperation
	IndexOperation
}

TransactionOperation represents a transaction operation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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