Documentation ¶
Index ¶
- func Scan(rows *sql.Rows, dest interface{}) error
- func ScanResult(rows *sql.Rows, dest interface{}) error
- func ScanSlice(rows *sql.Rows, dest interface{}) error
- type DB
- func (db *DB) Begin() (*Tx, error)
- func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (db *DB) Query(query string, args ...interface{}) *RowsResult
- func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) *RowsResult
- func (db *DB) QueryRow(query string, args ...interface{}) *RowResult
- func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *RowResult
- func (db *DB) RawDB() *sql.DB
- type DefaultLogger
- func (l DefaultLogger) Debug(ctx context.Context, format string, v ...interface{})
- func (l DefaultLogger) Error(ctx context.Context, format string, v ...interface{})
- func (l DefaultLogger) Info(ctx context.Context, format string, v ...interface{})
- func (l DefaultLogger) Warn(ctx context.Context, format string, v ...interface{})
- type Dialect
- type DialectClientOption
- type DialectClientOptionPool
- type DialectConfig
- type DialectDSN
- type LoggerInterface
- type Mssql
- type Mysql
- type RowResult
- type RowsResult
- type Tx
- func (tx *Tx) Commit() error
- func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error)
- func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (tx *Tx) Query(query string, args ...interface{}) *RowsResult
- func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) *RowsResult
- func (tx *Tx) QueryRow(query string, args ...interface{}) *RowResult
- func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *RowResult
- func (tx *Tx) Rollback() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ScanResult ¶
Types ¶
type DB ¶
func (*DB) Begin ¶ added in v0.3.5
Begin starts a transaction. The default isolation level is dependent on the driver.
func (*DB) BeginTx ¶ added in v0.3.5
BeginTx starts a transaction.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to BeginTx is canceled.
The provided TxOptions is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.
func (*DB) Exec ¶ added in v0.3.4
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query
func (*DB) ExecContext ¶ added in v0.3.4
func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*DB) Query ¶
func (db *DB) Query(query string, args ...interface{}) *RowsResult
Query executes a query that returns RowsResult, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryContext ¶
func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) *RowsResult
QueryContext executes a query that returns RowsResult, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryRow ¶ added in v0.2.3
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
func (*DB) QueryRowContext ¶ added in v0.2.3
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
type DefaultLogger ¶
type DefaultLogger struct { }
func (DefaultLogger) Debug ¶
func (l DefaultLogger) Debug(ctx context.Context, format string, v ...interface{})
func (DefaultLogger) Error ¶
func (l DefaultLogger) Error(ctx context.Context, format string, v ...interface{})
type Dialect ¶
type Dialect struct { Clients map[string]*DB Configs DialectConfig // contains filtered or unexported fields }
func Open ¶
func Open(configs DialectConfig, log LoggerInterface) (*Dialect, error)
Init init all the database clients
func (*Dialect) CreateClient ¶
CreateClient create the db pool for the database
type DialectClientOption ¶ added in v0.5.0
type DialectClientOption struct { Host string `json:"host"` Port int `json:"port"` User string `json:"user"` Password string `json:"password"` Database string `json:"database"` Dialect string `json:"dialect"` Logging *bool `json:"logging"` Pool *DialectClientOptionPool `json:"pool"` Charset string `json:"charset"` DialectOptions map[string]string `json:"dialectOptions"` }
type DialectClientOptionPool ¶ added in v0.5.1
type DialectConfig ¶
type DialectConfig struct { Clients map[string]*DialectClientOption `json:"clients"` Default *DialectClientOption `json:"default"` }
type DialectDSN ¶
type DialectDSN interface {
GetDialectDSN(database string, config *DialectClientOption) string
}
type LoggerInterface ¶
type Mssql ¶
type Mssql struct { }
Mssql mssql dialector
func (Mssql) GetDialectDSN ¶
func (m Mssql) GetDialectDSN(database string, config *DialectClientOption) string
GetDialectDSN
**config:{ "clients": { "share":{ "host": "127.0.0.1", "user": "sa", "password": "test123", "database": "test" }, "test":{ "host": "127.0.0.1", "port": 1433, "user": "sa", "password": "test123", "database": "test", "pool": { "maxIdleConns": 20, "maxLeftTime": 60000, "maxOpenConns": 50 }, "dialectOptions": { "dial timeout": "10" } } }, "default": { "port": 1433, "dialect": "sqlserver", "pool": { "maxIdleConns": 2, "maxLeftTime": 60000, "maxOpenConns": 5 }, "dialectOptions": { "dial timeout": "3" } } }
*
type Mysql ¶
type Mysql struct { }
Mysql mysql dialector
func (Mysql) GetDialectDSN ¶
func (m Mysql) GetDialectDSN(database string, config *DialectClientOption) string
GetDialectDSN
**config:{ "clients": { "share":{ "host": "127.0.0.1", "user": "test", "password": "test123", "database": "test" }, "test":{ "host": "127.0.0.1", "port": 3307, "user": "test", "password": "test123", "database": "test", "pool": { "maxIdleConns": 20, "maxLeftTime": 60000, "maxOpenConns": 50 }, "dialectOptions": { "writeTimeout": "2000ms", "readTimeout": "2000ms", "timeout":"2000ms" } } }, "default": { "port": 3306, "dialect": "mysql", "pool": { "maxIdleConns": 2, "maxLeftTime": 60000, "maxOpenConns": 5 }, "dialectOptions": { "writeTimeout": "3000ms", "readTimeout": "3000ms", "timeout":"3000ms" } } }
*
type RowResult ¶
type RowResult struct { LastError error // contains filtered or unexported fields }
type RowsResult ¶
func (RowsResult) Close ¶
func (r RowsResult) Close() error
Close returns the connection to the connection pool
type Tx ¶ added in v0.3.5
func (*Tx) Exec ¶ added in v0.3.5
Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
func (*Tx) ExecContext ¶ added in v0.3.5
func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE.
func (*Tx) Query ¶ added in v0.3.5
func (tx *Tx) Query(query string, args ...interface{}) *RowsResult
Query executes a query that returns rows, typically a SELECT.
func (*Tx) QueryContext ¶ added in v0.3.5
func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) *RowsResult
QueryContext executes a query that returns rows, typically a SELECT.
func (*Tx) QueryRow ¶ added in v0.3.5
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
func (*Tx) QueryRowContext ¶ added in v0.3.5
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. Otherwise, the *Row's Scan scans the first selected row and discards the rest.