database

package
v0.0.0-...-f0f63f4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoDatabase is when there is no database connection.
	ErrNoDatabase = errors.New("no database connection is set")
)

Functions

func Migrate

func Migrate(l logger.ILog, con *mysql.Connection, changesets string) (*sqlx.DB, error)

Migrate will run the database migrations and will create the database if it does not exist.

Types

type DBW

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

DBW is a database wrapper that provides helpful utilities.

func New

func New(db *sqlx.DB, name string) *DBW

New returns a new database wrapper.

func (*DBW) AffectedRows

func (d *DBW) AffectedRows(result sql.Result) int

AffectedRows returns the number of rows affected by the query.

func (*DBW) Exec

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

Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.

func (*DBW) Get

func (d *DBW) Get(dest interface{}, query string, args ...interface{}) error

Get using this DB. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.

func (*DBW) Name

func (d *DBW) Name() string

Name returns the database name.

func (*DBW) QueryRowScan

func (d *DBW) QueryRowScan(dest interface{}, query string, args ...interface{}) error

QueryRowScan returns a single result.

func (*DBW) RecordExists

func (d *DBW) RecordExists(err error) (bool, error)

RecordExists returns if the record exists or not.

func (*DBW) RecordExistsString

func (d *DBW) RecordExistsString(err error, s string) (bool, string, error)

RecordExistsString returns the proper string is the record exists.

func (*DBW) Select

func (d *DBW) Select(dest interface{}, query string, args ...interface{}) error

Select using this DB. Any placeholder parameters are replaced with supplied args.

func (*DBW) SuppressNoRowsError

func (d *DBW) SuppressNoRowsError(err error) error

SuppressNoRowsError will return nil if the error is sql.ErrNoRows.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL