Documentation
¶
Index ¶
- type DBConfig
- type Database
- type PsqlDB
- func (d *PsqlDB) Exec(sql string, args ...interface{}) (sql.Result, error)
- func (d *PsqlDB) ExecReturning(sql string, args ...interface{}) (*sql.Rows, error)
- func (d *PsqlDB) QueryIn(sql string, args ...interface{}) (*sql.Rows, error)
- func (d *PsqlDB) SelectIn(out interface{}, sql string, args ...interface{}) error
- func (d *PsqlDB) SelectMany(out interface{}, sql string, args ...interface{}) error
- func (d *PsqlDB) SelectOne(out interface{}, sql string, args ...interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBConfig ¶
type DBConfig struct {
Driver string `json:"driver"`
Host string `json:"host"`
Port int `json:"port"`
EnableSSL bool `json:"enable_ssl"`
Username string `json:"username"`
Password string `json:"password"`
DBName string `json:"db_name"`
MaxIdleConnections int `json:"max_idle_connections"`
MaxOpenConnections int `json:"max_open_connections"`
}
DBConfig defines basic db config model
func ReadConfig ¶
ReadConfig defines method to read config file
type Database ¶
type Database interface {
// Selects one item, result will be stored in "out". It will be casted
SelectOne(out interface{}, sql string, args ...interface{}) error
// Selects multiple items, result will be stored in "out". It will be casted
SelectMany(out interface{}, sql string, args ...interface{}) error
// Queries for "SELECT <x> WHERE <y> in (...)". Got results in "out" interface (with casting)
SelectIn(out interface{}, sql string, args ...interface{}) error
// Queries for "SELECT <x> WHERE <y> in (...)". Got results in returning rows
QueryIn(sql string, args ...interface{}) (*sql.Rows, error)
// Executes an sql request, usually do not expect returning rows
Exec(sql string, args ...interface{}) (sql.Result, error)
// Executes an sql request, expect returning data (rows)
ExecReturning(sql string, args ...interface{}) (*sql.Rows, error)
}
This is a basic interface for self-use database. Just in case that it might be changed to use different types of databases, we can do it with out affecting the upper level
type PsqlDB ¶
type PsqlDB struct {
// contains filtered or unexported fields
}
PsqlDB create a new db struct
func (*PsqlDB) ExecReturning ¶
ExecReturning executes query, usually have return values as sql rows
func (*PsqlDB) QueryIn ¶
QueryIn executes "SELECT <x> WHERE <y> in (...)", result will be returned as sql rows
func (*PsqlDB) SelectIn ¶
SelectIn executes "SELECT <x> WHERE <y> in (...)", result in "out" (casted)
func (*PsqlDB) SelectMany ¶
SelectMany selects several items. result in "out" (casted)
Click to show internal directories.
Click to hide internal directories.