Documentation
¶
Index ¶
- Constants
- Variables
- func NewErrDatabaseExist(name string) error
- func NewErrDatabaseNotExist(name string) error
- func NewErrDatabaseOptionsInvalid(opts any) error
- func NewErrObjectNotExist(key Key) error
- func NewErrSchemaNotExist(name string) error
- type Collection
- type CollectionOperation
- type Database
- type DatabaseOperation
- type DatabaseOptions
- type Document
- type IndexOperation
- type Key
- type LimitOption
- type Object
- type OffsetOption
- type Option
- type Order
- type OrderOption
- type ResultSet
- type Schema
- type Store
- type StoreOperation
- type Transaction
- type TransactionOperation
- type TransactionOption
Constants ¶
const ( OrderNone = Order(0) OrderAsc = Order(1) OrderDesc = Order(2) )
Order options.
Variables ¶
var ( ErrNotExist = errors.New("not exist") ErrExist = errors.New("exist") ErrInvalid = errors.New("invalid") )
var NoLimit = int(0)
NoLimit represents a no limit option.
var NoOffset = uint(0)
NoOffset represents a no offset option.
Functions ¶
func NewErrDatabaseExist ¶ added in v1.3.0
func NewErrDatabaseNotExist ¶ added in v1.3.0
func NewErrDatabaseOptionsInvalid ¶ added in v1.3.0
func NewErrObjectNotExist ¶ added in v1.3.0
func NewErrSchemaNotExist ¶ added in v1.3.0
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
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 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 ¶
Object represents a store object.
func ReadAllObjects ¶ added in v1.3.4
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 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 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.