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) 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
- type Dialect
- type DialectConfig
- type DialectDSN
- type LoggerInterface
- type Mssql
- type Mysql
- type RowResult
- type RowsResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ScanResult ¶
Types ¶
type DB ¶
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. 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.
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(format string, v ...interface{})
func (DefaultLogger) Error ¶
func (l DefaultLogger) Error(format string, v ...interface{})
func (DefaultLogger) Info ¶
func (l DefaultLogger) Info(format string, v ...interface{})
func (DefaultLogger) Warn ¶
func (l DefaultLogger) Warn(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 DialectConfig ¶
type DialectDSN ¶
type LoggerInterface ¶
type Mssql ¶
type Mssql struct { }
Mssql mssql dialector
func (Mssql) GetDialectDSN ¶
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 ¶
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