database

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 8 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"`
	UsernameSecret string `json:"username_secret"`
	Password       string `json:"password" config_obscure:"true"`
	PasswordSecret string `json:"password_secret"`
	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.

func (*Config) Validate added in v0.3.3

func (c *Config) Validate() error

type Cursor added in v0.3.3

type Cursor struct {
	Offset int64 `json:"offset"`
	Limit  int64 `json:"limit"`
}
var (
	EmptyCursor *Cursor = &Cursor{Offset: 0, Limit: 0}
)

func NewCursor added in v0.3.3

func NewCursor(offset, limit int64) *Cursor

func (Cursor) Valid added in v0.3.3

func (c Cursor) Valid() bool

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() error
}

type NullBool added in v0.3.3

type NullBool struct {
	sql.NullBool
}

func (NullBool) MarshalJSON added in v0.3.3

func (x NullBool) MarshalJSON() ([]byte, error)

type NullByte added in v0.3.3

type NullByte struct {
	sql.NullByte
}

func (NullByte) MarshalJSON added in v0.3.3

func (x NullByte) MarshalJSON() ([]byte, error)

type NullFloat64 added in v0.3.3

type NullFloat64 struct {
	sql.NullFloat64
}

func (NullFloat64) MarshalJSON added in v0.3.3

func (x NullFloat64) MarshalJSON() ([]byte, error)

type NullInt16 added in v0.3.3

type NullInt16 struct {
	sql.NullInt16
}

func (NullInt16) MarshalJSON added in v0.3.3

func (x NullInt16) MarshalJSON() ([]byte, error)

type NullInt32 added in v0.3.3

type NullInt32 struct {
	sql.NullInt32
}

func (NullInt32) MarshalJSON added in v0.3.3

func (x NullInt32) MarshalJSON() ([]byte, error)

type NullInt64 added in v0.3.3

type NullInt64 struct {
	sql.NullInt64
}

func (NullInt64) MarshalJSON added in v0.3.3

func (x NullInt64) MarshalJSON() ([]byte, error)

type NullString added in v0.3.3

type NullString struct {
	sql.NullString
}

func (NullString) MarshalJSON added in v0.3.3

func (x NullString) MarshalJSON() ([]byte, error)

type NullTime added in v0.3.3

type NullTime struct {
	sql.NullTime
}

func (NullTime) MarshalJSON added in v0.3.3

func (x NullTime) MarshalJSON() ([]byte, error)

type Tx

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

func (*Tx) Commit

func (tx *Tx) Commit() error

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