Documentation
¶
Index ¶
- Variables
- func ImportToDB(db *sql.Tx, fh io.Reader) error
- type Configuration
- type Instance
- type Migratable
- type Operator
- func (o Operator) GetByID(ctx context.Context, db Instance, columns []string, id int64) (Persistable, error)
- func (o Operator) GetByQuery(ctx context.Context, db Instance, columns []string, clause string, ...) ([]Persistable, error)
- func (o Operator) GetOneByQuery(ctx context.Context, db Instance, columns []string, clause string, ...) (Persistable, error)
- func (o Operator) InsertByQuery(ctx context.Context, db Instance, obj Persistable, columns []string, ...) (int64, error)
- func (o Operator) Migrate(ctx context.Context, db Instance) error
- func (o Operator) UpdateByQuery(ctx context.Context, db Instance, obj Persistable, columns []string, ...) (int64, error)
- type Persistable
- type Scanner
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMalformedDNS is the error returned if the database DSN does not adhere // to the expected format. ErrMalformedDNS = fmt.Errorf("DSN should have format 'name://source'") // ErrUnsupportedDriver is the error returned if the DSN does not specify // either mysql://, or sqlite:// as driver name. ErrUnsupportedDriver = fmt.Errorf("unsupported database driver") // ErrNoConnection is the error returned if database actions are performed // without establishing a connection (pool) with the database. ErrNoConnection = fmt.Errorf("no connection") // ErrImportFailed is the error returned if a sequence of sql statements to // import failed. ErrImportFailed = fmt.Errorf("failed to import sql code") // ErrNotFound is the error returned if the requested object does not exist // in the database. ErrNotFound = fmt.Errorf("object not found") // ErrInsertFailed is the error returned if the insert failed. ErrInsertFailed = fmt.Errorf("failed to insert") // ErrUpdateFailed is the error returned if the update failed. ErrUpdateFailed = fmt.Errorf("failed to update") // ErrQueryFailed is the error returned if a database statement failed. ErrQueryFailed = fmt.Errorf("query failed") // ErrUnknownColumn is the error returned if a specified column is unknown // for the Persistable. ErrUnknownColumn = fmt.Errorf("unknown column") )
Functions ¶
Types ¶
type Configuration ¶
type Configuration struct {
// DSN is the URI of the database to connect to.
DSN string `` /* 133-byte string literal not displayed */
// ConnMaxLifetime is the maximum amount of time a connection may be reused.
ConnMaxLifetime time.Duration `` /* 147-byte string literal not displayed */
// MaxIdleConns is the maximum amount of idle connections in the pool.
MaxIdleConns int `` /* 129-byte string literal not displayed */
// MaxOpenConns is the maximum amount of open connections to the database.
MaxOpenConns int `` /* 133-byte string literal not displayed */
// PingTimeout is the maximum time a ping will wait for a response.
PingTimeout time.Duration `` /* 132-byte string literal not displayed */
}
Configuration is the structure with database settings.
type Instance ¶
type Instance struct {
// Pool is the database connection pool.
Pool *sql.DB
// contains filtered or unexported fields
}
Instance is a database instance with a connection pool.
func Connect ¶
func Connect(cfg Configuration) (Instance, error)
Connect creates a database.Instance based on the provided Configuration.
type Migratable ¶
Migratable is an interface for a PErsistable model that has migration code to make structure adjustments between versions.
type Operator ¶
type Operator struct {
Table string
NewPersistable func() Persistable
}
Operator provides a collection of functions to store and retrieve a Persistable in the database.
func (Operator) GetByID ¶
func (o Operator) GetByID(ctx context.Context, db Instance, columns []string, id int64) (Persistable, error)
GetByID returns a persistable model by the primary key.
func (Operator) GetByQuery ¶
func (o Operator) GetByQuery(ctx context.Context, db Instance, columns []string, clause string, args ...interface{}) ([]Persistable, error)
GetByQuery returns zero or persistables by the provided query.
func (Operator) GetOneByQuery ¶
func (o Operator) GetOneByQuery(ctx context.Context, db Instance, columns []string, clause string, args ...interface{}) (Persistable, error)
GetOneByQuery returns a single persistable model by the provided query.
func (Operator) InsertByQuery ¶
func (o Operator) InsertByQuery(ctx context.Context, db Instance, obj Persistable, columns []string, clause string, args ...interface{}) (int64, error)
InsertByQuery adds a persistable to the database, with an optional query, and returns the newly inserted id.