Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type Database
- type PlainDB
- func (d *PlainDB) BuildTableName(tableName string) string
- func (d *PlainDB) DB() *sql.DB
- func (d *PlainDB) Driver() string
- func (d *PlainDB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (d *PlainDB) Init(o PlainDBOption) error
- func (d *PlainDB) Prefix() string
- func (d *PlainDB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (d *PlainDB) QueryRow(query string, args ...interface{}) *sql.Row
- func (d *PlainDB) SetDB(db *sql.DB)
- func (d *PlainDB) SetDriver(driver string)
- func (d *PlainDB) SetPrefix(prefix string)
- func (d *PlainDB) Table(tableName string) *PlainTable
- type PlainDBOption
- type PlainTable
- type Table
- type TxDB
Constants ¶
const DefaultConnMaxLifetimeInSecond = int64(30)
DefaultConnMaxLifetimeInSecond default conn max lifetime
Variables ¶
var ErrSetDriverFromTable = errors.New("herb:sql/db you can't execute set driver method in table interface")
ErrSetDriverFromTable error raised when execute SetDriver method of table .
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
//Driver sql driver.
Driver string
//Type sql database type.
Type string
//Conn sql conn string.
DataSource string
//Prefix sql table prefix.
Prefix string
//MaxIdleConns max idle conns.
MaxIdleConns int
//ConnMaxLifetimeInSecond conn max Lifetime in second.
ConnMaxLifetimeInSecond int64
//MaxOpenConns max open conns.
MaxOpenConns int
}
Config database config
type Database ¶
type Database interface {
//SetDB set sqlDB to database interface
SetDB(db *sql.DB)
//DB get sql DB of database.
DB() *sql.DB
//Driver return database drvier name.
Driver() string
//SetDriver set driver name.
SetDriver(string)
//BuildTableName return table name with giver table.
BuildTableName(table string) string
//Exec exec query with args.
Exec(query string, args ...interface{}) (sql.Result, error)
//Query exec query with args .
//Return rows.
Query(query string, args ...interface{}) (*sql.Rows, error)
//QueryRow exec query with args and rows.
//Return row.
QueryRow(query string, args ...interface{}) *sql.Row
}
Database database interface
type PlainDB ¶
type PlainDB struct {
// contains filtered or unexported fields
}
PlainDB plain database struct.
func (*PlainDB) BuildTableName ¶
BuildTableName return table name with giver table.
func (*PlainDB) Init ¶
func (d *PlainDB) Init(o PlainDBOption) error
Init init plain database with given option.
func (*PlainDB) Table ¶
func (d *PlainDB) Table(tableName string) *PlainTable
Table create plain table with given table name.
type PlainDBOption ¶
PlainDBOption plain database init option interface.
type PlainTable ¶
type PlainTable struct {
Database
// contains filtered or unexported fields
}
PlainTable plain table struct
func NewTable ¶
func NewTable(db Database, tableName string) *PlainTable
NewTable create plain table with given database and table name.
func (*PlainTable) BuildFieldName ¶
func (t *PlainTable) BuildFieldName(name string) string
BuildFieldName build field name with alias.
func (*PlainTable) SetDriver ¶
func (t *PlainTable) SetDriver(driver string)
SetDriver painc if execute SetDriver method of table.
func (*PlainTable) SetName ¶
func (t *PlainTable) SetName(table string)
SetName set plain table name.
func (*PlainTable) TableName ¶
func (t *PlainTable) TableName() string
TableName return table name build with database.
type Table ¶
type Table interface {
Database
//BuildFieldName return field name with given field.
BuildFieldName(field string) string
//SetAlias set table alias
SetAlias(string)
//Alias return table alias
Alias() string
//TableName return table name
TableName() string
}
Table table interface
type TxDB ¶
TxDB database wtih transaction.