Documentation
¶
Index ¶
- func CheckService(ser Service) error
- type BoltDatabase
- func (db *BoltDatabase) Bucket(name string, tx Tx) (*bolt.Bucket, error)
- func (db *BoltDatabase) Clear() error
- func (db *BoltDatabase) Close() error
- func (db *BoltDatabase) Create(m Model, ser Service, tx Tx) (int, error)
- func (db *BoltDatabase) Delete(id int, ser Service, tx Tx) error
- func (db *BoltDatabase) DoEach(first *int, skip *int, ser Service, tx Tx, ...) error
- func (db *BoltDatabase) DoMultiple(ids []int, ser Service, tx Tx, ...) error
- func (db *BoltDatabase) FindFirst(ser Service, tx Tx, match func(Model) (bool, error)) (Model, error)
- func (db *BoltDatabase) GetByID(id int, ser Service, tx Tx) (Model, error)
- func (db *BoltDatabase) GetRawByID(id int, ser Service, tx Tx) ([]byte, error)
- func (db *BoltDatabase) Transaction(writable bool, logic func(Tx) error) error
- func (db *BoltDatabase) Update(m Model, ser Service, tx Tx) error
- type BoltDatabaseConfig
- type BoltTx
- type DatabaseDriver
- type DatabaseService
- func (dbs *DatabaseService) Create(m Model, ser Service, tx Tx) (int, error)
- func (dbs *DatabaseService) Delete(id int, ser Service, tx Tx) error
- func (dbs *DatabaseService) DeleteFilter(ser Service, tx Tx, iff func(Model) bool) error
- func (dbs *DatabaseService) DeleteMultiple(ids []int, first *int, ser Service, tx Tx, iff func(Model) bool) error
- func (dbs *DatabaseService) GetAll(first *int, skip *int, ser Service, tx Tx) ([]Model, error)
- func (dbs *DatabaseService) GetFilter(first *int, skip *int, ser Service, tx Tx, keep func(m Model) bool) ([]Model, error)
- func (dbs *DatabaseService) GetMultiple(ids []int, ser Service, tx Tx, keep func(m Model) bool) ([]Model, error)
- func (dbs *DatabaseService) Update(m Model, ser Service, tx Tx) error
- type Model
- type ModelMetadata
- type PersistHookFunc
- type PersistHooks
- func (hooks *PersistHooks) PostCreateHook(m Model, ser Service, tx Tx) error
- func (hooks *PersistHooks) PostDeleteHook(m Model, ser Service, tx Tx) error
- func (hooks *PersistHooks) PostUpdateHook(m Model, ser Service, tx Tx) error
- func (hooks *PersistHooks) PreCreateHook(m Model, ser Service, tx Tx) error
- func (hooks *PersistHooks) PreDeleteHook(m Model, ser Service, tx Tx) error
- func (hooks *PersistHooks) PreUpdateHook(m Model, ser Service, tx Tx) error
- type Service
- type Tx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckService ¶
CheckService returns an error if the given service or its DB are nil.
Types ¶
type BoltDatabase ¶
BoltDatabase implements Database for boltDB.
func ConnectBoltDatabase ¶
func ConnectBoltDatabase(conf *BoltDatabaseConfig) (*BoltDatabase, error)
ConnectBoltDatabase connects to the database file at the given path and returns a new BoltDatabase pointer.
func (*BoltDatabase) Clear ¶
func (db *BoltDatabase) Clear() error
Clear removes all buckets in the given database.
func (*BoltDatabase) Close ¶
func (db *BoltDatabase) Close() error
Close closes the database connection.
func (*BoltDatabase) Delete ¶
func (db *BoltDatabase) Delete(id int, ser Service, tx Tx) error
Delete deletes the model with the given ID.
func (*BoltDatabase) DoEach ¶
func (db *BoltDatabase) DoEach(first *int, skip *int, ser Service, tx Tx, do func(Model, Service, Tx) (exit bool, err error), iff func(Model) bool) error
DoEach unmarshals and performs some function on each persisted element that passes the filter function.
func (*BoltDatabase) DoMultiple ¶
func (db *BoltDatabase) DoMultiple(ids []int, ser Service, tx Tx, do func(Model, Service, Tx) (exit bool, err error), iff func(Model) bool) error
DoMultiple unmarshals and performs some function on the persisted elements that pass the given filter function specified by the given IDs.
func (*BoltDatabase) FindFirst ¶
func (db *BoltDatabase) FindFirst( ser Service, tx Tx, match func(Model) (bool, error)) (Model, error)
FindFirst returns the first element that matches the conditions in the given function. Elements are iterated through in key order.
func (*BoltDatabase) GetByID ¶
GetByID retrieves the persisted Model with the given ID. The given service and its DB should not be nil.
func (*BoltDatabase) GetRawByID ¶
GetRawByID is a generic function that queries the given bucket in the given database for an entity of the given ID. The given DB pointer should not be nil.
func (*BoltDatabase) Transaction ¶
func (db *BoltDatabase) Transaction(writable bool, logic func(Tx) error) error
Transaction is a wrapper method that begins a transaction and passes it to the given function.
type BoltDatabaseConfig ¶
type BoltDatabaseConfig struct { Path string FileMode os.FileMode Buckets []string ClearOnClose bool }
BoltDatabaseConfig defines a set of options to be passed when opening a boltDB instance.
type BoltTx ¶
type BoltTx struct { DB *DatabaseService Tx *bolt.Tx }
BoltTx implements Transaction for boltDB.
func (*BoltTx) Database ¶
func (btx *BoltTx) Database() *DatabaseService
Database returns the database of the transaction.
type DatabaseDriver ¶
type DatabaseDriver interface { Transaction(writable bool, logic func(Tx) error) error Close() error DoMultiple(ids []int, ser Service, tx Tx, do func(Model, Service, Tx) (exit bool, err error), iff func(Model) bool) error DoEach(first *int, skip *int, ser Service, tx Tx, do func(Model, Service, Tx) (exit bool, err error), iff func(Model) bool) error FindFirst(ser Service, tx Tx, match func(Model) (exit bool, err error)) (Model, error) Create(m Model, ser Service, tx Tx) (int, error) Update(m Model, ser Service, tx Tx) error // Delete marks the model with the given ID as deleted. Delete(id int, ser Service, tx Tx) error GetByID(id int, ser Service, tx Tx) (Model, error) GetRawByID(id int, ser Service, tx Tx) ([]byte, error) }
DatabaseDriver defines generic CRUD logic for a database backend.
type DatabaseService ¶
type DatabaseService struct {
DatabaseDriver
}
DatabaseService provides
func (*DatabaseService) Delete ¶
func (dbs *DatabaseService) Delete(id int, ser Service, tx Tx) error
Delete deletes an existing persisted instance of a Model type.
func (*DatabaseService) DeleteFilter ¶
DeleteFilter deletes all the persisted instances of a Model type that pass the filer function.
func (*DatabaseService) DeleteMultiple ¶
func (dbs *DatabaseService) DeleteMultiple(ids []int, first *int, ser Service, tx Tx, iff func(Model) bool) error
DeleteMultiple deletes the existing persisted instances of a Model type specified by the given IDs.
func (*DatabaseService) GetAll ¶
GetAll retrieves all persisted instances of a Model type with the given data layer service.
See GetFilter for details on `first` and `skip`.
func (*DatabaseService) GetFilter ¶
func (dbs *DatabaseService) GetFilter(first *int, skip *int, ser Service, tx Tx, keep func(m Model) bool) ([]Model, error)
GetFilter retrieves all persisted instances of a Model type that pass the filter.
Collection begins on the first valid element after skipping the `skip` valid elements and continues for `first` valid elements that pass the filter. If `skip` is given as nil, collection begins with the first valid element. If `first` is given as nil, collection continues until the last persisted element is queried. The given service and its DB should not be nil. A nil filter function passes all.
func (*DatabaseService) GetMultiple ¶
func (dbs *DatabaseService) GetMultiple(ids []int, ser Service, tx Tx, keep func(m Model) bool) ([]Model, error)
GetMultiple retrieves the persisted instances of a Model type with the given IDs.
See GetFilter for details on `first` and `skip`.
type ModelMetadata ¶
type ModelMetadata struct { ID int CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time Version int }
ModelMetadata contains information about
type PersistHookFunc ¶
PersistHookFunc is a callback used as a hook function.
type PersistHooks ¶
type PersistHooks struct { PreCreateHooks []PersistHookFunc PostCreateHooks []PersistHookFunc PreUpdateHooks []PersistHookFunc PostUpdateHooks []PersistHookFunc PreDeleteHooks []PersistHookFunc PostDeleteHooks []PersistHookFunc }
PersistHooks provides hook functions to be called before and after service operations.
func (*PersistHooks) PostCreateHook ¶
func (hooks *PersistHooks) PostCreateHook(m Model, ser Service, tx Tx) error
PostCreateHook executes all hook functions designated to be called after create operations.
func (*PersistHooks) PostDeleteHook ¶
func (hooks *PersistHooks) PostDeleteHook(m Model, ser Service, tx Tx) error
PostDeleteHook executes all hook functions designated to be called after delete operations.
func (*PersistHooks) PostUpdateHook ¶
func (hooks *PersistHooks) PostUpdateHook(m Model, ser Service, tx Tx) error
PostUpdateHook executes all hook functions designated to be called after update operations.
func (*PersistHooks) PreCreateHook ¶
func (hooks *PersistHooks) PreCreateHook(m Model, ser Service, tx Tx) error
PreCreateHook executes all hook functions designated to be called before create operations.
func (*PersistHooks) PreDeleteHook ¶
func (hooks *PersistHooks) PreDeleteHook(m Model, ser Service, tx Tx) error
PreDeleteHook executes all hook functions designated to be called before delete operations.
func (*PersistHooks) PreUpdateHook ¶
func (hooks *PersistHooks) PreUpdateHook(m Model, ser Service, tx Tx) error
PreUpdateHook executes all hook functions designated to be called before update operations.
type Service ¶
type Service interface { Bucket() string Clean(m Model, tx Tx) error Validate(m Model, tx Tx) error Initialize(m Model, tx Tx) error PersistOldProperties(n Model, o Model, tx Tx) error PersistHooks() *PersistHooks Marshal(m Model) ([]byte, error) Unmarshal(buf []byte) (Model, error) }
Service provides various functions to operate on Models. All implementations should use type assertions to guarantee prevention of runtime errors.
type Tx ¶
type Tx interface { Database() *DatabaseService Unwrap() interface{} }
Tx defines a wrapper for database transactions objects.