Documentation ¶
Index ¶
- Variables
- func GetNonTransactionalContext(ctx context.Context) context.Context
- func GetRecordKeyPath(key RecordKey) string
- func GetRecordKind(key RecordKey) string
- func GetTransaction(ctx context.Context) interface{}
- func InsertWithRandomID(c context.Context, r Record, generateID IDGenerator, attempts int, ...) error
- func IsNotFound(err error) bool
- func NewContextWithTransaction(ctx context.Context, tx interface{}) context.Context
- func NewErrNotFoundByKey(record Record, cause error) error
- type Changes
- type Database
- type Deleter
- type EntityLoader
- type EntitySaver
- type ErrDuplicateUser
- type ErrNotFoundByKey
- type Getter
- type IDGenerator
- type InsertOption
- type InsertOptions
- type Inserter
- type MultiDeleter
- type MultiGetter
- type MultiSetter
- type MultiUpdater
- type Property
- type RandomStringOptions
- type Record
- type RecordKey
- type RecordRef
- type RecordWithIntID
- type RecordWithStrID
- type Session
- type Setter
- type Transaction
- type TransactionCoordinator
- type TransactionOption
- type TransactionOptions
- type TypeOfID
- type Updater
- type Upserter
- type Validatable
Constants ¶
This section is empty.
Variables ¶
var ErrNotSupported = errors.New("not supported")
ErrNotSupported - return this if db driver does not support requested operation. (for example no support for transactions)
var ( // ErrRecordNotFound is returned when a DB record is not found ErrRecordNotFound = errors.New("Record not found") )
Functions ¶
func GetNonTransactionalContext ¶
GetNonTransactionalContext returns non transaction context (e.g. parent of transactional context) TODO: This is can be dangerous if child context creates a new context with a deadline for example
func GetRecordKeyPath ¶
func GetRecordKind ¶
func GetTransaction ¶
GetTransaction returns original transaction object
func InsertWithRandomID ¶
func IsNotFound ¶
IsNotFound check if underlying error is ErrRecordNotFound
func NewContextWithTransaction ¶
NewContextWithTransaction stores transaction and original context into a transactional context
func NewErrNotFoundByKey ¶
NewErrNotFoundByKey creates an error that indicates that entity was not found by ID
Types ¶
type Changes ¶
type Changes struct {
// contains filtered or unexported fields
}
Changes accumulates DB changes
func (Changes) EntityHolders ¶
EntityHolders returns list of entity holders
func (*Changes) FlagAsChanged ¶
FlagAsChanged flags a record as changed
func (Changes) HasChanges ¶
HasChanges returns true if there are changes
type Database ¶
type Database interface { TransactionCoordinator Session }
Database is an interface that define a DB provider
type Deleter ¶
Deleter is an interface that describe DB provider that can delete a single record by key
type EntityLoader ¶
EntityLoader loads properties to struct
type EntitySaver ¶
EntitySaver dumps struct to properties
type ErrDuplicateUser ¶
type ErrDuplicateUser struct { // TODO: Should it be moved out of this package to strongo/app/user? SearchCriteria string DuplicateUserIDs []int64 }
ErrDuplicateUser indicates there is a duplicate user // TODO: move to strongo/app?
func (ErrDuplicateUser) Error ¶
func (err ErrDuplicateUser) Error() string
Error implements error interface
type ErrNotFoundByKey ¶
ErrNotFoundByKey indicates error was not found by ID
type InsertOption ¶
type InsertOption func(options *insertOptions)
func WithIDGenerator ¶
func WithIDGenerator(idGenerator IDGenerator) InsertOption
func WithRandomStringID ¶
func WithRandomStringID(length int) InsertOption
type InsertOptions ¶
type InsertOptions interface {
IDGenerator() IDGenerator
}
func NewInsertOptions ¶
func NewInsertOptions(opts ...InsertOption) InsertOptions
type Inserter ¶
type Inserter interface {
Insert(c context.Context, record Record, options InsertOptions) error
}
Inserter is an interface that describe DB provider that can insert a single entity with a specific or random ID
type MultiDeleter ¶
type MultiGetter ¶
MultiGetter is an interface that describe DB provider that can get multiple records at once (batch mode)
type MultiSetter ¶
MultiSetter is an interface that describe DB provider that can set multiple records at once (batch mode)
type MultiUpdater ¶
MultiUpdater is an interface that describe DB provider that can update multiple records at once (batch mode)
type RandomStringOptions ¶
type RandomStringOptions interface {
Length() int
}
type Record ¶
type Record interface { Key() RecordKey Data() Validatable SetData(data Validatable) Validate() error }
Record is an interface a struct should satisfy to comply with "strongo/db" library
func CreateEntityHoldersWithIntIDs ¶
func CreateEntityHoldersWithIntIDs(ids []int64, newRecord func() RecordWithIntID) (records []Record)
func NewRecord ¶
func NewRecord(key RecordKey, data Validatable) Record
type RecordKey ¶
type RecordKey = []RecordRef
RecordKey represents a full path to a given record (1 item in case of root recordset)
func NewRecordKey ¶
NewRecordKey creates a new record key from a sequence of record's references
type RecordRef ¶
type RecordRef struct { Kind string `json:"kind"` ID interface{} `json:"id"` // Usually string or int }
RecordRef hold a reference to a single record within a root or nested recordset.
type RecordWithIntID ¶
type RecordWithStrID ¶
type Session ¶
type Session interface { Inserter Upserter Getter Setter Updater Deleter MultiGetter MultiSetter MultiUpdater MultiDeleter }
Session defines interface
type Transaction ¶
type Transaction interface { Session }
type TransactionCoordinator ¶
type TransactionCoordinator interface { RunInTransaction( ctx context.Context, f func(ctx context.Context, tx Transaction) error, options ...TransactionOption, ) error }
TransactionCoordinator provides methods to work with transactions
type TransactionOption ¶
type TransactionOption func(options *transactionOptions)
func WithCrossGroup ¶
func WithCrossGroup() TransactionOption
func WithPassword ¶
func WithPassword(password string) TransactionOption
func WithReadonly ¶
func WithReadonly() TransactionOption
type TransactionOptions ¶
func NewTransactionOptions ¶
func NewTransactionOptions(opts ...TransactionOption) TransactionOptions
type Updater ¶
Updater is an interface that describe DB provider that can update a single EXISTING record by a key
type Upserter ¶
Upserter is an interface that describe DB provider that can upsert a single record by key
type Validatable ¶
type Validatable interface {
Validate() error
}
func VoidData ¶
func VoidData() Validatable