Documentation ¶
Index ¶
- Constants
- Variables
- func GenericCount(dbp DBProvider, filter yaormfilter.Filter) (uint64, error)
- func GenericDelete(m Model) (int64, error)
- func GenericInsert(m Model) error
- func GenericSave(m Model) error
- func GenericSelectOneFromModel(dbp DBProvider, m Model) error
- func GenericSelectOneWithModel(dbp DBProvider, filter yaormfilter.Filter, m Model) error
- func GenericUpdate(m Model) error
- func RegisterDB(config *DatabaseConfiguration) error
- func SaveWithPrimaryKeys(m Model, keys []string) error
- func UnregisterDB(name string) error
- type DB
- type DBProvider
- type DBSpecific
- type DMS
- type DatabaseCapacity
- type DatabaseConfiguration
- type DatabaseModel
- func (dm *DatabaseModel) DBHookBeforeDelete() error
- func (dm *DatabaseModel) DBHookBeforeInsert() error
- func (dm *DatabaseModel) DBHookBeforeUpdate() error
- func (dm *DatabaseModel) Delete() error
- func (dm *DatabaseModel) GetDBP() DBProvider
- func (dm *DatabaseModel) Load(dbp DBProvider) error
- func (dm *DatabaseModel) Save() error
- func (dm *DatabaseModel) SetDBP(dbp DBProvider)
- type DefaultExecutorHook
- func (h DefaultExecutorHook) AfterDelete(ctx context.Context, query string, args ...interface{})
- func (h DefaultExecutorHook) AfterExec(ctx context.Context, query string, args ...interface{})
- func (h DefaultExecutorHook) AfterInsert(ctx context.Context, query string, args ...interface{})
- func (h DefaultExecutorHook) AfterSelect(ctx context.Context, query string, args ...interface{})
- func (h DefaultExecutorHook) AfterSelectOne(ctx context.Context, query string, args ...interface{})
- func (h DefaultExecutorHook) AfterUpdate(ctx context.Context, query string, args ...interface{})
- func (h DefaultExecutorHook) BeforeDelete(ctx context.Context, query string, args ...interface{})
- func (h DefaultExecutorHook) BeforeExec(ctx context.Context, query string, args ...interface{})
- func (h DefaultExecutorHook) BeforeInsert(ctx context.Context, query string, args ...interface{})
- func (h DefaultExecutorHook) BeforeSelect(ctx context.Context, query string, args ...interface{})
- func (h DefaultExecutorHook) BeforeSelectOne(ctx context.Context, query string, args ...interface{})
- func (h DefaultExecutorHook) BeforeUpdate(ctx context.Context, query string, args ...interface{})
- type ExecutorHook
- type Model
- type PostgresSpecific
- type SqlExecutor
- func (e *SqlExecutor) Delete(list ...interface{}) (int64, error)
- func (e *SqlExecutor) Exec(query string, args ...interface{}) (sql.Result, error)
- func (e *SqlExecutor) Insert(list ...interface{}) error
- func (e *SqlExecutor) Select(i interface{}, query string, args ...interface{}) ([]interface{}, error)
- func (e *SqlExecutor) SelectOne(holder interface{}, query string, args ...interface{}) error
- func (e *SqlExecutor) Update(list ...interface{}) (int64, error)
- type SubqueryloadFunc
- type Table
- func (t Table) FieldIndex(field string) int
- func (t Table) Fields() []string
- func (t Table) FieldsWithoutPK() []string
- func (t Table) FilterFieldIndex(field string) int
- func (t Table) KeyFields() map[string]int
- func (t Table) Keys() []string
- func (t Table) Name() string
- func (t Table) NameForQuery(dbp DBProvider) string
- func (t Table) NewFilter() (yaormfilter.Filter, error)
- func (t Table) NewModel() (Model, error)
- func (t Table) NewSlice() (interface{}, error)
- func (t Table) NewSlicePtr() (interface{}, error)
- func (t *Table) WithAutoIncrement(v bool) *Table
- func (t *Table) WithFilter(f yaormfilter.Filter) *Table
- func (t *Table) WithKeys(keys []string) *Table
- func (t *Table) WithSchema(schema string) *Table
- func (t *Table) WithSubqueryloading(fn SubqueryloadFunc, mapperField string) *Table
- type TypeConverter
Constants ¶
const ( DatabaseCapacitySchema = iota ^ 42 DatabaseCapacityUUID )
Variables ¶
var ( // ErrTableEmpty is returned when a registered model has no exported fields ErrTableEmpty = errors.Errorf("Table is empty") // ErrTableNotFound is returned when a table cannot be found ErrTableNotFound = errors.NotFoundf("Table") // ErrDbNotFound is returned when a database cannot be found ErrDbNotFound = errors.NotFoundf("Database") )
var (
ErrDatabaseConflict = errors.Errorf("Database name conflicts with existing")
)
Functions ¶
func GenericCount ¶
func GenericCount(dbp DBProvider, filter yaormfilter.Filter) (uint64, error)
GenericCount selects counts the row in the database panics if filter or dbp is nil
func GenericDelete ¶ added in v1.1.0
GenericDelete will delete the provided model from its database Returns the number of rows deleted
func GenericInsert ¶
GenericInsert inserts the provided model in the database panics if model is nil or not linked to dbp
func GenericSave ¶
GenericSave updates or inserts the provided model in the database panics if model is nil or not linked to dbp
func GenericSelectOneFromModel ¶
func GenericSelectOneFromModel(dbp DBProvider, m Model) error
GenericSelectOneFromModel selects one row in the database from a model value panics if filter or dbp is nil
func GenericSelectOneWithModel ¶
func GenericSelectOneWithModel(dbp DBProvider, filter yaormfilter.Filter, m Model) error
GenericSelectOneWithModel selects one row in the database providing the destination model directly panics if filter or dbp is nil
func GenericUpdate ¶
GenericUpdate updates the provided model in the database panics if model is nil or not linked to dbp
func RegisterDB ¶
func RegisterDB(config *DatabaseConfiguration) error
RegisterDB creates a new database with configuration
func SaveWithPrimaryKeys ¶
SaveWithPrimaryKeys updates or inserts the provided model in the database, using the provided keys to check if it exists
func UnregisterDB ¶
UnregisterDB removes the database from the registry
Types ¶
type DB ¶
type DB interface { zesty.DB System() DMS ExecutorHook() ExecutorHook DBSpecific() DBSpecific }
type DBProvider ¶
type DBProvider interface { zesty.DBProvider EscapeValue(value string) string CanSelectForUpdate() bool Context() context.Context UUID() string HasCapacity(capacity DatabaseCapacity) bool RunInTransaction(func() error) error // contains filtered or unexported methods }
DBProvider provides an abstracted way of accessing the database
func NewDBProvider ¶
func NewDBProvider(ctx context.Context, name string) (DBProvider, error)
NewDBProvider creates a new db provider
type DBSpecific ¶ added in v1.2.0
type DBSpecific interface { // OnSessionCreated is a function executed once per DBProvider instance OnSessionCreated(DBProvider) error }
DBSpecific is an interface describing how specificities of each DMS are handled in yaorm
type DMS ¶
type DMS uint8
DMS represents a database management system
Database management systems.
func (DMS) DriverName ¶
DriverName returns the name of the driver for ds.
func (DMS) RekordoValue ¶
RekordoValue returns the rekordo value
type DatabaseCapacity ¶
type DatabaseCapacity int8
DatabaseCapacity describes multiple capacities provided only by some databases systems
type DatabaseConfiguration ¶
type DatabaseConfiguration struct { Name string System DMS DSN string MaxOpenConns int MaxIdleConns int ConnMaxLifetime time.Duration ConnMaxIdleTime time.Duration AutoCreateTables bool // Dialect database dialect, leave empty for automatic guessing Dialect gorp.Dialect // ExecutorHook is a configurable hook to add logs, for example, to your sql requests ExecutorHook ExecutorHook DBSpecific DBSpecific }
DatabaseConfiguration configures a database
type DatabaseModel ¶
type DatabaseModel struct {
// contains filtered or unexported fields
}
DatabaseModel is the struct every model should compose
func (*DatabaseModel) DBHookBeforeDelete ¶ added in v1.1.0
func (dm *DatabaseModel) DBHookBeforeDelete() error
DBHookBeforeDelete is a hook called before performing a DB delete By default, this function does not do anything. If needed, you will have to implement this function in your structure composing this one in order to have your code hook executed
func (*DatabaseModel) DBHookBeforeInsert ¶
func (dm *DatabaseModel) DBHookBeforeInsert() error
DBHookBeforeInsert is a hook called before performing a DB insertion By default, this function does not do anything. If needed, you will have to implement this function in your structure composing this one in order to have your code hook executed
func (*DatabaseModel) DBHookBeforeUpdate ¶
func (dm *DatabaseModel) DBHookBeforeUpdate() error
DBHookBeforeUpdate is a hook called before performing a DB update By default, this function does not do anything. If needed, you will have to implement this function in your structure composing this one in order to have your code hook executed
func (*DatabaseModel) Delete ¶
func (dm *DatabaseModel) Delete() error
Delete removes the model from database In order to be usable, this function needs to be redfined by each composition of this structure
func (*DatabaseModel) GetDBP ¶
func (dm *DatabaseModel) GetDBP() DBProvider
GetDBP should return the DBProvider tied to this model
func (*DatabaseModel) Load ¶
func (dm *DatabaseModel) Load(dbp DBProvider) error
Load loads the model from database given the current struct In order to be usable, this function needs to be redfined by each composition of this structure
func (*DatabaseModel) Save ¶
func (dm *DatabaseModel) Save() error
Save allows saving the model In order to be usable, this function needs to be redfined by each composition of this structure
func (*DatabaseModel) SetDBP ¶
func (dm *DatabaseModel) SetDBP(dbp DBProvider)
SetDBP allows setting a DBProvider to the model, then returned by GetDBP
type DefaultExecutorHook ¶
type DefaultExecutorHook struct{}
DefaultExecutorHook is the default executor hook, returned if no hook has been defined This struct can be composed by any of your executor hooks to avoid having to define every handler
func (DefaultExecutorHook) AfterDelete ¶
func (h DefaultExecutorHook) AfterDelete(ctx context.Context, query string, args ...interface{})
AfterDelete is a hook executed before performing a Delete action on gorp sql executor
func (DefaultExecutorHook) AfterExec ¶ added in v1.2.0
func (h DefaultExecutorHook) AfterExec(ctx context.Context, query string, args ...interface{})
AfterExec is a hook executed before performing an Exec action on gorp sql executor
func (DefaultExecutorHook) AfterInsert ¶
func (h DefaultExecutorHook) AfterInsert(ctx context.Context, query string, args ...interface{})
AfterInsert is a hook executed before performing an Insert action on gorp sql executor
func (DefaultExecutorHook) AfterSelect ¶
func (h DefaultExecutorHook) AfterSelect(ctx context.Context, query string, args ...interface{})
AfterSelect is a hook executed before performing a Select action on gorp sql executor
func (DefaultExecutorHook) AfterSelectOne ¶
func (h DefaultExecutorHook) AfterSelectOne(ctx context.Context, query string, args ...interface{})
AfterSelectOne is a hook executed before performing a SelectOne action on gorp sql executor
func (DefaultExecutorHook) AfterUpdate ¶
func (h DefaultExecutorHook) AfterUpdate(ctx context.Context, query string, args ...interface{})
AfterUpdate is a hook executed before performing an Update action on gorp sql executor
func (DefaultExecutorHook) BeforeDelete ¶
func (h DefaultExecutorHook) BeforeDelete(ctx context.Context, query string, args ...interface{})
BeforeDelete is a hook executed before performing a Delete action on gorp sql executor
func (DefaultExecutorHook) BeforeExec ¶ added in v1.2.0
func (h DefaultExecutorHook) BeforeExec(ctx context.Context, query string, args ...interface{})
BeforeExec is a hook executed before performing an Exec action on gorp sql executor
func (DefaultExecutorHook) BeforeInsert ¶
func (h DefaultExecutorHook) BeforeInsert(ctx context.Context, query string, args ...interface{})
BeforeInsert is a hook executed before performing an Insert action on gorp sql executor
func (DefaultExecutorHook) BeforeSelect ¶
func (h DefaultExecutorHook) BeforeSelect(ctx context.Context, query string, args ...interface{})
BeforeSelect is a hook executed before performing a Select action on gorp sql executor
func (DefaultExecutorHook) BeforeSelectOne ¶
func (h DefaultExecutorHook) BeforeSelectOne(ctx context.Context, query string, args ...interface{})
BeforeSelectOne is a hook executed before performing a SelectOne action on gorp sql executor
func (DefaultExecutorHook) BeforeUpdate ¶
func (h DefaultExecutorHook) BeforeUpdate(ctx context.Context, query string, args ...interface{})
BeforeUpdate is a hook executed before performing an Update action on gorp sql executor
type ExecutorHook ¶
type ExecutorHook interface { BeforeSelectOne(ctx context.Context, query string, args ...interface{}) AfterSelectOne(ctx context.Context, query string, args ...interface{}) BeforeSelect(ctx context.Context, query string, args ...interface{}) AfterSelect(ctx context.Context, query string, args ...interface{}) BeforeInsert(ctx context.Context, query string, args ...interface{}) AfterInsert(ctx context.Context, query string, args ...interface{}) BeforeUpdate(ctx context.Context, query string, args ...interface{}) AfterUpdate(ctx context.Context, query string, args ...interface{}) BeforeDelete(ctx context.Context, query string, args ...interface{}) AfterDelete(ctx context.Context, query string, args ...interface{}) BeforeExec(ctx context.Context, query string, args ...interface{}) AfterExec(ctx context.Context, query string, args ...interface{}) }
ExecutorHook can be implemented and set on the database handler Before every query, a new object will be created to provide a way to perform operations, like logging / timing your sql queries
type Model ¶
type Model interface { // GetDBP should return the DBProvider tied to this model GetDBP() DBProvider // SetDBP allows setting a DBProvider to the model, then returned by GetDBP SetDBP(dbp DBProvider) // Save allows saving the model Save() error // Load loads the model from database given the current struct Load(dbp DBProvider) error // Delete removes the model from database Delete() error // DBHookBeforeInsert is a hook called before performing a DB insertion DBHookBeforeInsert() error // DBHookBeforeUpdate is a hook called before performing a DB update DBHookBeforeUpdate() error // DBHookBeforeDelete is a hook called before performing a DB delete DBHookBeforeDelete() error }
Model is the interface every model should implement from
func GenericSelectAll ¶
func GenericSelectAll(dbp DBProvider, filter yaormfilter.Filter) ([]Model, error)
GenericSelectAll selects all rows in the database panics if filter or dbp is nil
func GenericSelectOne ¶
func GenericSelectOne(dbp DBProvider, filter yaormfilter.Filter) (Model, error)
GenericSelectOne selects one row in the database panics if filter or dbp is nil
type PostgresSpecific ¶ added in v1.2.0
type PostgresSpecific struct { // IntervaStyle holds the style of output of the interval // See Postgres manual 8.5.5 IntervalStyle string }
PostgresSpecific holds specific configurations used by Postgres
func (PostgresSpecific) OnSessionCreated ¶ added in v1.2.0
func (p PostgresSpecific) OnSessionCreated(dbp DBProvider) error
OnSessionCreated is executed when a Session is created. This function will use the: - IntervalStyle
type SqlExecutor ¶
type SqlExecutor struct { gorp.SqlExecutor // contains filtered or unexported fields }
SqlExecutor is a custom SQL Executor, on top of the one provided by gorp used to provide multiple hooks before executing statements
func (*SqlExecutor) Delete ¶
func (e *SqlExecutor) Delete(list ...interface{}) (int64, error)
Delete is a handler to delete a list of models from the database
func (*SqlExecutor) Exec ¶ added in v1.2.0
func (e *SqlExecutor) Exec(query string, args ...interface{}) (sql.Result, error)
Exec is a handler to execute a SQL query
func (*SqlExecutor) Insert ¶
func (e *SqlExecutor) Insert(list ...interface{}) error
Insert is a handler to insert a list of models inside the database
func (*SqlExecutor) Select ¶
func (e *SqlExecutor) Select(i interface{}, query string, args ...interface{}) ([]interface{}, error)
Select is a handler to select multiple rows from database and return them
func (*SqlExecutor) SelectOne ¶
func (e *SqlExecutor) SelectOne(holder interface{}, query string, args ...interface{}) error
SelectOne is a handler to select only 1 row from database and store it inside the first argument
func (*SqlExecutor) Update ¶
func (e *SqlExecutor) Update(list ...interface{}) (int64, error)
Update is a handler to update a list of models inside the database
type SubqueryloadFunc ¶
type SubqueryloadFunc func(dbp DBProvider, ids []interface{}) (interface{}, error)
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is the type hosting all the table characteristics
func GetTableByFilter ¶
func GetTableByFilter(f yaormfilter.Filter) (*Table, error)
GetTableByFilter returns the table using this filter
func GetTableByModel ¶
GetTableByModel returns the table registered for this model
func (Table) FieldIndex ¶
func (Table) FieldsWithoutPK ¶
func (Table) FilterFieldIndex ¶
func (Table) NameForQuery ¶
func (t Table) NameForQuery(dbp DBProvider) string
NameForQuery returns the name that should be used for SQL queries
func (Table) NewSlicePtr ¶
func (*Table) WithAutoIncrement ¶
func (*Table) WithFilter ¶
func (t *Table) WithFilter(f yaormfilter.Filter) *Table
func (*Table) WithSchema ¶
func (*Table) WithSubqueryloading ¶
func (t *Table) WithSubqueryloading(fn SubqueryloadFunc, mapperField string) *Table
type TypeConverter ¶
type TypeConverter struct{}
TypeConverter defines conversion from db to golang
func (TypeConverter) FromDb ¶
func (tc TypeConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
FromDb converts to golang
func (TypeConverter) ToDb ¶
func (tc TypeConverter) ToDb(val interface{}) (interface{}, error)
ToDb converts to database
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
_vendor
|
|
github.com/lann/builder
Package builder provides a method for writing fluent immutable builders.
|
Package builder provides a method for writing fluent immutable builders. |
github.com/lann/ps
Fully persistent data structures.
|
Fully persistent data structures. |
github.com/lann/squirrel
Package squirrel provides a fluent SQL generator.
|
Package squirrel provides a fluent SQL generator. |
github.com/loopfz/gadgeto/zesty
zesty is based on gorp, and abstracts DB transaction specifics.
|
zesty is based on gorp, and abstracts DB transaction specifics. |
github.com/satori/go.uuid
Package uuid provides implementation of Universally Unique Identifier (UUID).
|
Package uuid provides implementation of Universally Unique Identifier (UUID). |