Documentation
¶
Index ¶
- Constants
- type DB
- func (db *DB) Begin() error
- func (db *DB) Close()
- func (db *DB) Commit() error
- func (db *DB) DB() (ret *sql.DB)
- func (db *DB) Error() error
- func (db *DB) Exec(query string, args ...interface{}) (ret sql.Result, err error)
- func (db *DB) Ping() error
- func (db *DB) Prepare(query string, args ...interface{}) (*sql.Stmt, error)
- func (db *DB) Query(query string, args ...interface{}) (ret *sql.Rows, err error)
- func (db *DB) QueryRow(query string, args ...interface{}) (ret *sql.Row)
- func (db *DB) Rollback() error
- func (db *DB) SetConnMaxLifetime(d time.Duration)
- func (db *DB) SetMaxIdleConns(n int)
- func (db *DB) SetMaxOpenConns(n int)
- type DriverName
- type Dsn
- type DsnConf
Constants ¶
const ( MySQL = DriverName("mysql") PostgreSQL = DriverName("postgres") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a database object.
func New ¶
func New(dn DriverName, dsn Dsn) *DB
New returns a new *DB. If error, error is set in *DB.err. You can get *DB.err with *DB.Error ().
func (*DB) Commit ¶
Commit commits the transacrion. Begin needs to be executed before this method is executed.
func (*DB) Exec ¶
Exec executes a prepared statement with the specified arguments. And this method returns a Result summarizing the effect of the statement.
func (*DB) Query ¶
The query executes a prepared query statement with the specified arguments and returns the query result as *sql.Rows.
func (*DB) QueryRow ¶
QueryRow executes a prepared query statement with the specified arguments. Scans the first selected line and returns it as *sql.Row. It will be destroyed after that.
func (*DB) Rollback ¶
Rollback rolls back transaction. Begin needs to be executed before this method is executed.
func (*DB) SetConnMaxLifetime ¶
SetConnMaxLifetime sets the maximum amount of time a connection may be reused. Expired connections may be closed lazily before reuse. If d <= 0, connections are reused forever.
func (*DB) SetMaxIdleConns ¶
SetMaxIdleConns sets the maximum number of connections in the idle connection pool. If MaxOpenConns is greater than 0 but less than the new MaxIdleConns then the new MaxIdleConns will be reduced to match the MaxOpenConns limit If n <= 0, no idle connections are retained.
func (*DB) SetMaxOpenConns ¶
SetMaxOpenConns sets the maximum number of open connections to the database. If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than MaxIdleConns, then MaxIdleConns will be reduced to match the new MaxOpenConns limit If n <= 0, then there is no limit on the number of open connections. The default is 0 (unlimited).
type DriverName ¶ added in v0.2.0
type DriverName string
func (DriverName) String ¶ added in v0.2.0
func (dn DriverName) String() string
String returns the converted string from of DriverName.