Documentation
¶
Index ¶
- func Pairs(params ...interface{}) map[string]interface{}
- type ConnectionString
- type DBLink
- func (l *DBLink) Bool(sqlQuery string, args ...interface{}) bool
- func (l *DBLink) Connect() error
- func (l *DBLink) Database() *sql.DB
- func (l *DBLink) Delete(table string, wherePairs map[string]interface{}) (int64, error)
- func (l *DBLink) Disconnect()
- func (l *DBLink) Exec(sqlQuery string, args ...interface{}) (int64, error)
- func (l *DBLink) Exists(sqlQuery string, args ...interface{}) (bool, error)
- func (l *DBLink) GetBool(sqlQuery string, args ...interface{}) (bool, error)
- func (l *DBLink) GetCount(sqlQuery string, args ...interface{}) (int64, error)
- func (l *DBLink) GetFloat64(sqlQuery string, args ...interface{}) (float64, error)
- func (l *DBLink) GetInt(sqlQuery string, args ...interface{}) (int, error)
- func (l *DBLink) GetInt64(sqlQuery string, args ...interface{}) (int64, error)
- func (l *DBLink) GetJSONMap(sqlQuery string, args ...interface{}) (map[string]interface{}, error)
- func (l *DBLink) GetJSONStruct(target interface{}, sqlQuery string, args ...interface{}) error
- func (l *DBLink) GetMany(sqlQuery string, args ...interface{}) (Resultset, error)
- func (l *DBLink) GetOne(sqlQuery string, args ...interface{}) (Row, error)
- func (l *DBLink) GetString(sqlQuery string, args ...interface{}) (string, error)
- func (l *DBLink) GetTime(sqlQuery string, args ...interface{}) (time.Time, error)
- func (l *DBLink) GetTimef(format, sqlQuery string, args ...interface{}) (string, error)
- func (l *DBLink) Insert(table string, pairs map[string]interface{}) error
- func (l *DBLink) InsertID(table string, pairs map[string]interface{}, idFieldName ...string) (int64, error)
- func (l *DBLink) InsertUUID(table string, pairs map[string]interface{}, idFieldName ...string) (string, error)
- func (l *DBLink) IsEmptyErr(err error) bool
- func (l *DBLink) MustGetBool(sqlQuery string, args ...interface{}) (bool, error)
- func (l *DBLink) MustGetFloat64(sqlQuery string, args ...interface{}) (float64, error)
- func (l *DBLink) MustGetInt(sqlQuery string, args ...interface{}) (int, error)
- func (l *DBLink) MustGetInt64(sqlQuery string, args ...interface{}) (int64, error)
- func (l *DBLink) MustGetJSONMap(sqlQuery string, args ...interface{}) (map[string]interface{}, error)
- func (l *DBLink) MustGetJSONStruct(target interface{}, sqlQuery string, args ...interface{}) error
- func (l *DBLink) MustGetMany(sqlQuery string, args ...interface{}) (Resultset, error)
- func (l *DBLink) MustGetString(sqlQuery string, args ...interface{}) (string, error)
- func (l *DBLink) MustGetTime(sqlQuery string, args ...interface{}) (time.Time, error)
- func (l *DBLink) MustGetTimef(format, sqlQuery string, args ...interface{}) (string, error)
- func (l *DBLink) SetEmergencyCallback(ec func(error))
- func (l *DBLink) Update(table string, updatePairs map[string]interface{}, ...) (int64, error)
- type DBLinkOptions
- type Resultset
- func (r Resultset) Bottom() bool
- func (r Resultset) Count() int
- func (r Resultset) JSON(errorIfEmpty bool) (string, error)
- func (r Resultset) Map() []map[string]interface{}
- func (r *Resultset) Next() bool
- func (r *Resultset) Rewind()
- func (r *Resultset) Row() (Row, error)
- func (r *Resultset) Rows() ([]Row, error)
- func (r Resultset) Top() bool
- type Row
- func (r Row) Bool(key string) bool
- func (r Row) Columns() []string
- func (r Row) Float64(key string) float64
- func (r Row) Int(key string) int
- func (r Row) Int64(key string) int64
- func (r Row) JSON() (string, error)
- func (r Row) JSONMap(key string) (map[string]interface{}, bool)
- func (r Row) JSONStruct(key string, target interface{}) error
- func (r Row) Map() map[string]interface{}
- func (r Row) Ready() bool
- func (r Row) String(key string) string
- func (r Row) Time(key string) time.Time
- func (r Row) Timef(key, format string) time.Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConnectionString ¶
type ConnectionString struct {
// contains filtered or unexported fields
}
ConnectionString has directives to obtain database connection string To create a new ConnectionString, use ConnStringDirect(), ConnStringEnvVar()
func ConnStringDirect ¶
func ConnStringDirect(val string) *ConnectionString
ConnStringDirect sets connection string with given value
func ConnStringEnvVar ¶
func ConnStringEnvVar(key string) *ConnectionString
ConnStringEnvVar configures the engine to obtain connection string from given environment variable
type DBLink ¶
type DBLink struct { DBLinkOptions // connection options // contains filtered or unexported fields }
DBLink is the basic interface between developer and database instance
func New ¶
func New(opts *DBLinkOptions) (*DBLink, error)
New returns an instance of database, configured with options.
func NewConnected ¶
func NewConnected(opts *DBLinkOptions) (*DBLink, error)
NewConnected returns an already connected instance of dbLink, ready for use
func (*DBLink) Bool ¶
Bool returns the query result's single value as a boolean. in case of any error, it returns false
func (*DBLink) Database ¶
Database returns the raw sql driver database connection, aimed to let the programmer execute transactions and advanced operations
func (*DBLink) Delete ¶
Delete executes "delete" statements against specific table, considering the mandatory "where" criteria The routine tries to return affected rows count.
func (*DBLink) Disconnect ¶
func (l *DBLink) Disconnect()
Disconnect closes the link with database or database pool
func (*DBLink) Exec ¶
Exec sends the given sql query to database server. typically update, delete and insert, and return the number of affected rows
func (*DBLink) GetFloat64 ¶
GetFloat64 returns the query result's single value as a float64
func (*DBLink) GetJSONMap ¶
GetJSONMap returns the query result's single column value as map
func (*DBLink) GetJSONStruct ¶
GetJSONStruct tries to scan query result's single column value into given struct
func (*DBLink) GetTimef ¶
GetTimef returns the query result's single value as a formatted time.Time, considering the given format string
func (*DBLink) InsertID ¶
func (l *DBLink) InsertID(table string, pairs map[string]interface{}, idFieldName ...string) (int64, error)
InsertID inserts a new record into given table and returns the last inserted id The 3rd param is the optional field name. If not given, the default value "id" will be used
func (*DBLink) InsertUUID ¶
func (l *DBLink) InsertUUID(table string, pairs map[string]interface{}, idFieldName ...string) (string, error)
InsertUUID inserts a new record into given table and returns the last inserted uuid The 3rd param is the optional field name. If not given, the default value "id" will be used
func (*DBLink) IsEmptyErr ¶
IsEmptyErr returns true if the given error is sql.ErrNoRows
func (*DBLink) MustGetBool ¶
MustGetBool returns the query result's single value as a boolean If sql.ErrNoRows occurs, it's returned. The other routines ( without "Must" preffix ) ignores sql.ErrNoRows
func (*DBLink) MustGetFloat64 ¶
MustGetFloat64 returns the query result's single value as a float64 If sql.ErrNoRows occurs, it's returned. The other routines ( without "Must" preffix ) ignores sql.ErrNoRows
func (*DBLink) MustGetInt ¶
MustGetInt returns the query result's single value as an int If sql.ErrNoRows occurs, it's returned. The other routines ( without "Must" preffix ) ignores sql.ErrNoRows
func (*DBLink) MustGetInt64 ¶
MustGetInt64 returns the query result's single value as an int64 If sql.ErrNoRows occurs, it's returned. The other routines ( without "Must" preffix ) ignores sql.ErrNoRows
func (*DBLink) MustGetJSONMap ¶
func (l *DBLink) MustGetJSONMap(sqlQuery string, args ...interface{}) (map[string]interface{}, error)
MustGetJSONMap returns the query result's single column value as map If sql.ErrNoRows occurs, it's returned. The other routines ( without "Must" preffix ) ignores sql.ErrNoRows
func (*DBLink) MustGetJSONStruct ¶
MustGetJSONStruct tries to scan query result's single column value into given struct If sql.ErrNoRows occurs, it's returned. The other routines ( without "Must" preffix ) ignores sql.ErrNoRows
func (*DBLink) MustGetMany ¶
MustGetMany returns sql query result as an array of map[string]string The difference to GetMany is that, if no record is found, it returns an error
func (*DBLink) MustGetString ¶
MustGetString returns the query result's single value as a string If sql.ErrNoRows occurs, it's returned. The other routines ( without "Must" preffix ) ignores sql.ErrNoRows
func (*DBLink) MustGetTime ¶
MustGetTime returns the query result's single value as a time.Time If sql.ErrNoRows occurs, it's returned. The other routines ( without "Must" preffix ) ignores sql.ErrNoRows
func (*DBLink) MustGetTimef ¶
MustGetTimef returns the query result's single value as a formatted time.Time, considering the given format string If sql.ErrNoRows occurs, it's returned. The other routines ( without "Must" preffix ) ignores sql.ErrNoRows
func (*DBLink) SetEmergencyCallback ¶
SetEmergencyCallback defines a routine to log emergency "no-connection" messages
func (*DBLink) Update ¶
func (l *DBLink) Update(table string, updatePairs map[string]interface{}, wherePairs map[string]interface{}) (int64, error)
Update executes "update" sql queries against database At least one whereParameters is mandatory. Important: WHERE only accepts "AND" where criteria. If you need to send more complex operations/statements, use Execute()
type DBLinkOptions ¶
type DBLinkOptions struct {
// contains filtered or unexported fields
}
DBLinkOptions contains directives for config database connection To create an instance, use Options() function
func Options ¶
func Options(cs *ConnectionString, connTimeout, execTimeout, connAttemptsMax, connAttemptsMaxMinutes, secondsBetweenReconnectionAttempts uint, debugPrint bool) *DBLinkOptions
Options is a helper to initializate a new DBLinkOptions structure reconnectionAttemptsMax is the max number of (re)connection attempts. If zeroed, keeps trying indefinitely or until reconnectionAttemptsMaxMinutes is reached. reconnectionAttemptsMaxMinutes is the max allowed time to insist in (re)connect. If zeroed, keeps trying undefinetely or until reconnectionAttemptsMax is reached intervalBetweenReconnectionAttemptsSeconds is the sleepin' time lapse between (re)connection attempts debugPrint if true, prints debug/log messages to stdout with stdlib log.Printf() function
type Resultset ¶
type Resultset struct {
// contains filtered or unexported fields
}
Resultset contains rows and result metadata
func (Resultset) Map ¶
Map returns the resultset as a []map[string]interface{} If the resultset is empty, returns nil
func (*Resultset) Next ¶
Next returns true if there's a next item and position the internal cursonr on it
type Row ¶
type Row struct {
// contains filtered or unexported fields
}
Row holds a single record
func (Row) Float64 ¶
Float64 returns the specified field as float64 Check for conversion details: https://stackoverflow.com/questions/31946344/why-does-go-treat-a-postgresql-numeric-decimal-columns-as-uint8
func (Row) JSONMap ¶
JSONMap returns the column content desserialized and a bool indicating if the map has some content
func (Row) JSONStruct ¶
JSONStruct returns the column content desserialized to given target struct
Source Files
¶
- connectionstring.go
- dblink.go
- dblinkoptions.go
- delete.go
- execute.go
- exists.go
- getbool.go
- getcount.go
- getfloat64.go
- getint.go
- getint64.go
- getintarray.go
- getjsonmap.go
- getjsonstruct.go
- getmany.go
- getone.go
- getstring.go
- getstringarray.go
- gettime.go
- gettimef.go
- insert.go
- insertid.go
- insertuuid.go
- mustgetmany.go
- pairs.go
- pgkebab.go
- resultset.go
- row.go
- update.go