store

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2025 License: Apache-2.0 Imports: 5 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 NewErrDatabaseExist added in v1.3.0

func NewErrDatabaseExist(name string) error

func NewErrDatabaseNotExist added in v1.3.0

func NewErrDatabaseNotExist(name string) error

func NewErrDatabaseOptionsInvalid added in v1.3.0

func NewErrDatabaseOptionsInvalid(opts any) error

func NewErrObjectNotExist added in v1.3.0

func NewErrObjectNotExist(key Key) error

func NewErrSchemaNotExist added in v1.3.0

func NewErrSchemaNotExist(name string) error

Types

type Collection added in v0.9.0

type Collection = document.Collection

type CollectionOperation added in v1.3.4

type CollectionOperation interface {
	// InsertObject puts a document object with the specified primary key.
	InsertObject(ctx context.Context, docKey Key, obj Object) error
	// FindObjects returns a result set matching the specified key.
	FindObjects(ctx context.Context, docKey Key, opts ...Option) (ResultSet, error)
	// UpdateObject updates a document object with the specified primary key.
	UpdateObject(ctx context.Context, docKey Key, obj Object) error
	// RemoveObject removes a document object with the specified primary key.
	RemoveObject(ctx context.Context, docKey Key) error
	// RemoveObjects removes document objects with the specified primary key.
	RemoveObjects(ctx context.Context, docKey Key) error
	// TruncateObjects removes all document objects.
	TruncateObjects(ctx context.Context) error
}

CollectionOperation represents collection operations.

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 {
	// ListCollections returns the all collection in the database.
	ListCollections(ctx context.Context) ([]Collection, error)
	// CreateCollection creates a new collection into the database.
	CreateCollection(ctx context.Context, col Collection) error
	// UpdateCollection updates the specified collection in the database.
	UpdateCollection(ctx context.Context, col Collection) error
	// LookupCollection returns the specified collection in the database.
	LookupCollection(ctx context.Context, name string) (Collection, error)
	// RemoveCollection removes the specified collection in the database.
	RemoveCollection(ctx context.Context, name string) error
	// TruncateCollections removes all collections in the database.
	TruncateCollections(ctx context.Context) error
}

DatabaseOperation represents database operations.

type DatabaseOptions added in v0.9.0

type DatabaseOptions = map[string]interface{}

DatabaseOptions represents a database options.

type Document added in v1.3.4

type Document interface {
	// Key returns a key of the document.
	Key() Key
	// Object returns a object of the document.
	Object() Object
}

Document represents a store document.

func NewDocument added in v1.3.4

func NewDocument(key Key, obj Object) Document

NewDocument returns a new document.

type IndexOperation

type IndexOperation interface {
	// InsertIndex puts a secondary index with the primary key.
	InsertIndex(ctx context.Context, idxKey Key) error
	// RemoveIndex removes the specified secondary index.
	RemoveIndex(ctx context.Context, idxKey Key) error
	// FindObjectsByIndex returns a result set matching the specified index key.
	FindObjectsByIndex(ctx context.Context, idxKey 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.

func ReadAllObjects added in v1.3.4

func ReadAllObjects(rs ResultSet) ([]Object, error)

ReadAllObjects reads all objects from the result set.

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
	// Document returns a document in the current cursor.
	Document() (Document, error)
}

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.
	LookupDatabase(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 StoreOperation added in v1.1.0

type StoreOperation interface {
	DatabaseOperation
	CollectionOperation
	IndexOperation
}

StoreOperation represents a transaction operation.

type Transaction

type Transaction interface {
	TransactionOperation
	StoreOperation
	// Database returns the transaction database.
	Database() Database
}

Transaction represents a transaction interface.

type TransactionOperation

type TransactionOperation interface {
	TransactionOption
	// Commit commits this transaction.
	Commit(ctx context.Context) error
	// Cancel cancels this transaction.
	Cancel(ctx context.Context) error
}

TransactionOperation represents a transaction operation.

type TransactionOption added in v1.1.0

type TransactionOption interface {
	// SetAutoCommit sets the auto commit flag.
	SetAutoCommit(bool)
	// IsAutoCommit returns true whether the auto commit flag is set.
	IsAutoCommit() bool
	// SetTimeout sets the timeout of this transaction.
	SetTimeout(t time.Duration) error
}

TransactionOption represents a transaction option.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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