Documentation
¶
Index ¶
- Constants
- Variables
- func GetActiveList() (nameList []name)
- func GetDSN(n name) string
- func IsTx(mx Mx) bool
- func JSON(rows *sql.Rows) (j []byte, err error)
- func Map(rows *sql.Rows) (res []map[string]interface{}, err error)
- func MapV1(rows *sql.Rows) (data []map[string]interface{}, err error)
- func MySQLErrorIs(err error, code int) bool
- func New(c ...Config) (err error)
- func Rommit(_log *ilog.Data, err error, txs ...*sql.Tx) error
- type Config
- type Mx
- type Sec
Constants ¶
View Source
const ( DataBaseName name = "DataBaseName_MYSQL_URL" DataBaseName_RO name = "DataBaseName_RO_MYSQL_URL" )
Variables ¶
View Source
var ConfigDefault = Config{
ConnMaxIdleTime: 0,
ConnMaxLifetime: 0,
MaxOpenConns: 10,
MaxIdleConns: 2,
}
Functions ¶
func GetActiveList ¶
func GetActiveList() (nameList []name)
func MySQLErrorIs ¶
func Rommit ¶
Rommit :
使用條件有兩個:
[1] 需賦予 func 返回值變數名 ✔ 正確: func example() (err error) { } ✘ 錯誤: func example() (error) {} [2] 需要用在 defer 的 func 內,不能直接接在 defer 後面 ✔ 正確: defer func() { Rommit(_log, err, tx) }() ✘ 錯誤: defer Rommit(_log, err, tx) [3] 要使用追蹤 err 範圍(在有 [1] 的前提下) ✔ 支援: bar, err = foo() bar, err := foo() switch bar, err = foo(); {} if bar, err = foo(); err != nil {} if err = foo(); err != nil {} ✘ 不支援: switch bar, err := foo(); {} if bar, err := foo(); err != nil {} if err := foo(); err != nil {}
運作邏輯:
if err != nil { rollback() } else { commit() }
Types ¶
type Mx ¶
type Mx interface { QueryRow(query string, args ...any) *sql.Row Query(query string, args ...any) (*sql.Rows, error) Exec(query string, args ...any) (sql.Result, error) Prepare(query string) (*sql.Stmt, error) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) }
Click to show internal directories.
Click to hide internal directories.