db

package
v1.8.81 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.8.77

type Config struct {
	Host string
	Name string
	User string
	Pass string
}

type IDB

type IDB interface {
	Close()
	NamedExec(query string, arg interface{}) (sql.Result, error)
	Exec(query string, args ...interface{}) (sql.Result, error)
	Get(dest interface{}, query string, args ...interface{}) error
	Select(dest interface{}, query string, args ...interface{}) error
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
	ExecMany(stmts []string, chunkSize int) (e error)
	Host() string // The host name (from config)
	Name() string // The name of the database (from config)
	Query(query string, args ...interface{}) (*sql.Rows, error)
}

IDB is a container for db interactions

func NewMySQL added in v1.8.78

func NewMySQL(config *Config, log log.ILog) IDB

New returns a new MySQL object

type MySQL added in v1.8.77

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

MySQL is mysql

func (*MySQL) BeginTx added in v1.8.77

func (m *MySQL) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx starts a transaction.

The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to BeginTx is canceled.

The provided TxOptions is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.

func (*MySQL) Close added in v1.8.77

func (m *MySQL) Close()

Close closes the database and prevents new queries from starting. Close then waits for all queries that have started processing on the server to finish.

It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.

func (*MySQL) Exec added in v1.8.77

func (m *MySQL) 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 (*MySQL) ExecMany added in v1.8.77

func (m *MySQL) ExecMany(stmts []string, chunkSize int) (e error)

UpdateMany updates a slice of User objects in chunks

func (*MySQL) Get added in v1.8.77

func (m *MySQL) 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 (*MySQL) Host added in v1.8.77

func (m *MySQL) Host() string

func (*MySQL) Name added in v1.8.77

func (m *MySQL) Name() string

func (*MySQL) NamedExec added in v1.8.77

func (m *MySQL) NamedExec(query string, arg interface{}) (sql.Result, error)

NamedExec using this DB. Any named placeholder parameters are replaced with fields from arg.

func (*MySQL) Query added in v1.8.78

func (m *MySQL) Query(query string, args ...interface{}) (*sql.Rows, error)

func (*MySQL) Select added in v1.8.77

func (m *MySQL) Select(dest interface{}, query string, args ...interface{}) error

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

Jump to

Keyboard shortcuts

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