Documentation
¶
Index ¶
- func CloseAll() []exception.Exception
- func GetInstance(instanceName string) (*sql.DB, exception.Exception)
- type Adapter
- func (a *Adapter) Eject() *sql.DB
- func (a *Adapter) ExecContext(ktx kontext.Context, queryKey, query string, args ...interface{}) (Result, exception.Exception)
- func (a *Adapter) Ping(ktx kontext.Context) exception.Exception
- func (a *Adapter) QueryContext(ktx kontext.Context, queryKey, query string, args ...interface{}) (Rows, exception.Exception)
- func (a *Adapter) QueryRowContext(ktx kontext.Context, queryKey, query string, args ...interface{}) Row
- func (a *Adapter) Transaction(ktx kontext.Context, transactionKey string, f func(tx TX) exception.Exception) exception.Exception
- type Config
- type DB
- type Option
- type Result
- type ResultAdapter
- type Row
- type RowAdapter
- type Rows
- type RowsAdapter
- type TX
- type TXAdapter
- func (t *TXAdapter) ExecContext(ctx kontext.Context, queryKey, query string, args ...interface{}) (Result, exception.Exception)
- func (t *TXAdapter) QueryContext(ctx kontext.Context, queryKey, query string, args ...interface{}) (Rows, exception.Exception)
- func (t *TXAdapter) QueryRowContext(ctx kontext.Context, queryKey, query string, args ...interface{}) Row
- type Transactionable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
An Adapter for golang sql
func (*Adapter) ExecContext ¶
func (a *Adapter) ExecContext(ktx kontext.Context, queryKey, query string, args ...interface{}) (Result, exception.Exception)
ExecContext wrap sql ExecContext function
func (*Adapter) QueryContext ¶
func (a *Adapter) QueryContext(ktx kontext.Context, queryKey, query string, args ...interface{}) (Rows, exception.Exception)
QueryContext wrap sql QueryContext function
type Config ¶
type Config struct { Username string Password string Host string // If port is empty it will return 3306 instead Port string Name string // contains filtered or unexported fields }
Config carry all database config in a single struct
type DB ¶
type DB interface { Ping(ktx kontext.Context) exception.Exception Transactionable TX Eject() *sql.DB }
DB is database interface wrapper for *sql.DB
type Option ¶
type Option func(*Config)
Option when fabricating connection
func WithConnMaxLifetime ¶
WithConnMaxLifetime fabricate connection with max connection lifetime
func WithMaxIdleConn ¶
WithMaxIdleConn fabricate connection with max idle connection
func WithMaxOpenConn ¶
WithMaxOpenConn fabricate connection with max open connection
type Result ¶
type Result interface { // LastInsertId returns the integer generated by the database // in response to a command. Typically this will be from an // "auto increment" column when inserting a new row. Not all // databases support this feature, and the syntax of such // statements varies. LastInsertId() (int64, exception.Exception) // RowsAffected returns the number of rows affected by an // update, insert, or delete. Not every database or database // driver may support this. RowsAffected() (int64, exception.Exception) }
Result summarizes an executed SQL command.
type ResultAdapter ¶
type ResultAdapter struct {
// contains filtered or unexported fields
}
ResultAdapter wrap sql result
func (*ResultAdapter) LastInsertId ¶
func (r *ResultAdapter) LastInsertId() (int64, exception.Exception)
LastInsertId returns the integer generated by the database in response to a command. Typically this will be from an "auto increment" column when inserting a new row. Not all databases support this feature, and the syntax of such statements varies.
func (*ResultAdapter) RowsAffected ¶
func (r *ResultAdapter) RowsAffected() (int64, exception.Exception)
RowsAffected returns the number of rows affected by an update, insert, or delete. Not every database or database driver may support this.
type RowAdapter ¶
type RowAdapter struct {
// contains filtered or unexported fields
}
RowAdapter wrap single sql row
func (*RowAdapter) Scan ¶
func (r *RowAdapter) Scan(dest ...interface{}) exception.Exception
Scan warp default row scan function
type Rows ¶
type Rows interface { Close() exception.Exception Columns() ([]string, exception.Exception) Err() exception.Exception Next() bool NextResultSet() bool Scan(dest ...interface{}) exception.Exception }
Rows multiple result of database query
type RowsAdapter ¶
RowsAdapter wrap default sql.Rows struct
func (*RowsAdapter) Columns ¶
func (r *RowsAdapter) Columns() ([]string, exception.Exception)
Columns return rows column
func (*RowsAdapter) Scan ¶
func (r *RowsAdapter) Scan(dest ...interface{}) exception.Exception
Scan row
type TX ¶
type TX interface { ExecContext(ctx kontext.Context, queryKey, query string, args ...interface{}) (Result, exception.Exception) QueryContext(ctx kontext.Context, queryKey, query string, args ...interface{}) (Rows, exception.Exception) QueryRowContext(ctx kontext.Context, queryKey, query string, args ...interface{}) Row }
TX is database transaction
type TXAdapter ¶
type TXAdapter struct {
// contains filtered or unexported fields
}
A TXAdapter adapater for golang sql
func AdaptTXAdapter ¶
AdaptTXAdapter do adapting mysql transaction
func (*TXAdapter) ExecContext ¶
func (t *TXAdapter) ExecContext(ctx kontext.Context, queryKey, query string, args ...interface{}) (Result, exception.Exception)
ExecContext wrap sql ExecContext function