yaorm: github.com/geoffreybauduin/yaorm Index | Files | Directories

package yaorm

import "github.com/geoffreybauduin/yaorm"

Index

Package Files

databasecapacity.go db.go dbprovider.go dbspecific.go dbspecific_postgres.go executorhook.go filterapply.go model.go requestbuilder.go sqlexecutor.go subqueryload.go table.go typeconverter.go

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")
)

func GenericCount Uses

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 Uses

func GenericDelete(m Model) (int64, error)

GenericDelete will delete the provided model from its database Returns the number of rows deleted

func GenericInsert Uses

func GenericInsert(m Model) error

GenericInsert inserts the provided model in the database panics if model is nil or not linked to dbp

func GenericSave Uses

func GenericSave(m Model) error

GenericSave updates or inserts the provided model in the database panics if model is nil or not linked to dbp

func GenericSelectOneFromModel Uses

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 Uses

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 Uses

func GenericUpdate(m Model) error

GenericUpdate updates the provided model in the database panics if model is nil or not linked to dbp

func RegisterDB Uses

func RegisterDB(config *DatabaseConfiguration) error

RegisterDB creates a new database with configuration

func SaveWithPrimaryKeys Uses

func SaveWithPrimaryKeys(m Model, keys []string) error

SaveWithPrimaryKeys updates or inserts the provided model in the database, using the provided keys to check if it exists

func UnregisterDB Uses

func UnregisterDB(name string) error

UnregisterDB removes the database from the registry

type DB Uses

type DB interface {
    zesty.DB
    System() DMS
    ExecutorHook() ExecutorHook
    DBSpecific() DBSpecific
}

func GetDB Uses

func GetDB(name string) (DB, error)

GetDB returns a database object from its name

type DBProvider Uses

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 Uses

func NewDBProvider(ctx context.Context, name string) (DBProvider, error)

NewDBProvider creates a new db provider

type DBSpecific Uses

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 Uses

type DMS uint8

DMS represents a database management system

const (
    DatabasePostgreSQL DMS = iota ^ 42
    DatabaseMySQL
    DatabaseSqlite3
)

Database management systems.

func (DMS) DriverName Uses

func (d DMS) DriverName() string

DriverName returns the name of the driver for ds.

func (DMS) RekordoValue Uses

func (d DMS) RekordoValue() rekordo.DBMS

RekordoValue returns the rekordo value

type DatabaseCapacity Uses

type DatabaseCapacity int8

DatabaseCapacity describes multiple capacities provided only by some databases systems

type DatabaseConfiguration Uses

type DatabaseConfiguration struct {
    Name             string
    System           DMS
    DSN              string
    MaxOpenConns     int
    MaxIdleConns     int
    ConnMaxLifetime  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 Uses

type DatabaseModel struct {
    // contains filtered or unexported fields
}

DatabaseModel is the struct every model should compose

func (*DatabaseModel) DBHookBeforeDelete Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (dm *DatabaseModel) GetDBP() DBProvider

GetDBP should return the DBProvider tied to this model

func (*DatabaseModel) Load Uses

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 Uses

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 Uses

func (dm *DatabaseModel) SetDBP(dbp DBProvider)

SetDBP allows setting a DBProvider to the model, then returned by GetDBP

type DefaultExecutorHook Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (p PostgresSpecific) OnSessionCreated(dbp DBProvider) error

OnSessionCreated is executed when a Session is created. This function will use the: - IntervalStyle

type SqlExecutor Uses

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 Uses

func (e *SqlExecutor) Delete(list ...interface{}) (int64, error)

Delete is a handler to delete a list of models from the database

func (*SqlExecutor) Exec Uses

func (e *SqlExecutor) Exec(query string, args ...interface{}) (sql.Result, error)

Exec is a handler to execute a SQL query

func (*SqlExecutor) Insert Uses

func (e *SqlExecutor) Insert(list ...interface{}) error

Insert is a handler to insert a list of models inside the database

func (*SqlExecutor) Select Uses

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 Uses

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 Uses

func (e *SqlExecutor) Update(list ...interface{}) (int64, error)

Update is a handler to update a list of models inside the database

type SubqueryloadFunc Uses

type SubqueryloadFunc func(dbp DBProvider, ids []interface{}) (interface{}, error)

type Table Uses

type Table struct {
    // contains filtered or unexported fields
}

Table is the type hosting all the table characteristics

func GetTable Uses

func GetTable(dbName, tableName string) (*Table, error)

GetTable returns the table matching the parameters

func GetTableByFilter Uses

func GetTableByFilter(f yaormfilter.Filter) (*Table, error)

GetTableByFilter returns the table using this filter

func GetTableByModel Uses

func GetTableByModel(m Model) (*Table, error)

GetTableByModel returns the table registered for this model

func NewTable Uses

func NewTable(dbName, tableName string, model Model) *Table

NewTable registers a new table

func (Table) FieldIndex Uses

func (t Table) FieldIndex(field string) int

func (Table) Fields Uses

func (t Table) Fields() []string

func (Table) FieldsWithoutPK Uses

func (t Table) FieldsWithoutPK() []string

func (Table) FilterFieldIndex Uses

func (t Table) FilterFieldIndex(field string) int

func (Table) KeyFields Uses

func (t Table) KeyFields() map[string]int

func (Table) Keys Uses

func (t Table) Keys() []string

func (Table) Name Uses

func (t Table) Name() string

func (Table) NameForQuery Uses

func (t Table) NameForQuery(dbp DBProvider) string

NameForQuery returns the name that should be used for SQL queries

func (Table) NewFilter Uses

func (t Table) NewFilter() (yaormfilter.Filter, error)

func (Table) NewModel Uses

func (t Table) NewModel() (Model, error)

func (Table) NewSlice Uses

func (t Table) NewSlice() (interface{}, error)

func (Table) NewSlicePtr Uses

func (t Table) NewSlicePtr() (interface{}, error)

func (*Table) WithAutoIncrement Uses

func (t *Table) WithAutoIncrement(v bool) *Table

func (*Table) WithFilter Uses

func (t *Table) WithFilter(f yaormfilter.Filter) *Table

func (*Table) WithKeys Uses

func (t *Table) WithKeys(keys []string) *Table

func (*Table) WithSchema Uses

func (t *Table) WithSchema(schema string) *Table

func (*Table) WithSubqueryloading Uses

func (t *Table) WithSubqueryloading(fn SubqueryloadFunc, mapperField string) *Table

type TypeConverter Uses

type TypeConverter struct{}

TypeConverter defines conversion from db to golang

func (TypeConverter) FromDb Uses

func (tc TypeConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)

FromDb converts to golang

func (TypeConverter) ToDb Uses

func (tc TypeConverter) ToDb(val interface{}) (interface{}, error)

ToDb converts to database

Directories

PathSynopsis
tools
_vendor/github.com/lann/builderPackage builder provides a method for writing fluent immutable builders.
_vendor/github.com/lann/psFully persistent data structures.
_vendor/github.com/lann/squirrelPackage squirrel provides a fluent SQL generator.
_vendor/github.com/loopfz/gadgeto/zestyzesty is based on gorp, and abstracts DB transaction specifics.
_vendor/github.com/loopfz/gadgeto/zesty/utils/rekordo
_vendor/github.com/satori/go.uuidPackage uuid provides implementation of Universally Unique Identifier (UUID).
yaormfilter

Package yaorm imports 16 packages (graph). Updated 2020-04-02. Refresh now. Tools for package owners.