database

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: LGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Driver        string `json:"driver"`
	Username      string `json:"username"`
	Password      string `json:"password" config_obscure:"true"`
	Hostname      string `json:"hostname"`
	Port          int    `json:"port"`
	Database      string `json:"database"`
	BatchSize     int    `json:"batch_size"`
	SetPoolLimits bool   `json:"set_pool_limits"`
	MaxIdleConns  int    `json:"max_idle_conns"`
	MaxOpenConns  int    `json:"max_open_conns"`
	// contains filtered or unexported fields
}

SQL configuration structure.

func NewConfig

func NewConfig() *Config

Create a new configuration object.

func (*Config) ToDSN

func (c *Config) ToDSN() string

Return the DSN for this database configuration.

type Database

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

SQL proxy object.

This trainwreck exists so that we can make use of database interfaces.

It might be 100% useless, as `sql.DB` will most likely conform to `IDatabase`, so this file might vanish at some point.

func (*Database) Begin

func (db *Database) Begin() (*sql.Tx, error)

func (*Database) Beginx

func (db *Database) Beginx() (*sqlx.Tx, error)

func (*Database) Close

func (db *Database) Close() error

func (*Database) Exec

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

func (*Database) Get

func (db *Database) Get(what interface{}, query string, args ...interface{}) error

func (*Database) MustBegin

func (db *Database) MustBegin() *sqlx.Tx

func (*Database) NamedExec

func (db *Database) NamedExec(query string, args interface{}) (sql.Result, error)

func (*Database) Ping

func (db *Database) Ping() error

func (*Database) Prepare

func (db *Database) Prepare(query string) (*sql.Stmt, error)

func (*Database) Query

func (db *Database) Query(query string, args ...interface{}) (IRows, error)

func (*Database) QueryRowx

func (db *Database) QueryRowx(query string, args ...interface{}) IRow

func (*Database) Queryx

func (db *Database) Queryx(query string, args ...interface{}) (IRowsx, error)

func (*Database) Select

func (db *Database) Select(what interface{}, query string, args ...interface{}) error

func (*Database) SetMaxIdleConns

func (db *Database) SetMaxIdleConns(limit int)

func (*Database) SetMaxOpenConns

func (db *Database) SetMaxOpenConns(limit int)

type DatabaseMgr

type DatabaseMgr struct {
}

Database management.

This is a series of wrappers around Go's internal DB stuff to ensure that we set up max idle/open connections et al.

func (*DatabaseMgr) CheckDB

func (dbm *DatabaseMgr) CheckDB(db IDatabase) error

Check the db connection.

func (*DatabaseMgr) Open

func (dbm *DatabaseMgr) Open(driver string, dsn string) (IDatabase, error)

Open a connection to the database specified in the DSN string.

func (*DatabaseMgr) OpenConfig

func (dbm *DatabaseMgr) OpenConfig(conf *Config) (IDatabase, error)

Open and configure a database connection.

type IDatabase

type IDatabase interface {
	MustBegin() *sqlx.Tx
	Begin() (*sql.Tx, error)
	Beginx() (*sqlx.Tx, error)
	Close() error
	Exec(string, ...interface{}) (sql.Result, error)
	NamedExec(string, interface{}) (sql.Result, error)
	Ping() error
	Prepare(string) (*sql.Stmt, error)
	Query(string, ...interface{}) (IRows, error)
	Queryx(string, ...interface{}) (IRowsx, error)
	QueryRowx(string, ...interface{}) IRow
	Select(interface{}, string, ...interface{}) error
	Get(interface{}, string, ...interface{}) error
	SetMaxIdleConns(int)
	SetMaxOpenConns(int)
}

Interface for `sql.DB` objects.

func Open

func Open(driver string, dsn string) (IDatabase, error)

type IDatabaseMgr

type IDatabaseMgr interface {
	Open(string, string) (IDatabase, error)
	OpenConfig(*Config) (IDatabase, error)
	CheckDB(IDatabase) error
}

type IRow

type IRow interface {
	Err() error
	Scan(dest ...interface{}) error
}

Interface for `sql.Row` objects.

type IRows

type IRows interface {
	Close() error
	ColumnTypes() ([]*sql.ColumnType, error)
	Columns() ([]string, error)
	Err() error
	Next() bool
	NextResultSet() bool
	Scan(...interface{}) error
}

Interface for `sql.Rows` objects.

type IRowsx

type IRowsx interface {
	Close() error
	ColumnTypes() ([]*sql.ColumnType, error)
	Columns() ([]string, error)
	Err() error
	Next() bool
	NextResultSet() bool
	Scan(...interface{}) error
	StructScan(interface{}) error
}

Interface for `sqlx.Rows` objects.

type ITx

type ITx interface {
	NamedExec(string, interface{}) (sql.Result, error)
	Commit()
}

type Tx

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

func (*Tx) Commit

func (tx *Tx) Commit()

func (*Tx) NamedExec

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

Jump to

Keyboard shortcuts

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