Documentation ¶
Index ¶
- Constants
- Variables
- func AddAliasWthDB(aliasName, driverName string, db *sql.DB) error
- func AddDatabase(name string, c *Cache)
- func ColValue(opt operator, value interface{}) interface{}
- func Do(name, cmd string, to ...interface{}) (reply interface{}, err error)
- func GetConnects(name string) int
- func GetDB(aliasNames ...string) (*sql.DB, error)
- func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) error
- func RegisterDriver(driverName string, typ DriverType) error
- func ResetModelCache()
- func SetConnMaxLifetime(aliasName string, connMaxLifetime int)
- func SetDataBaseTZ(aliasName string, tz *time.Location) error
- func SetMaxIdleConns(aliasName string, maxIdleConns int)
- func SetMaxOpenConns(aliasName string, maxOpenConns int)
- func ToInt64(value interface{}) (d int64)
- func ToStr(value interface{}, args ...int) (s string)
- func Transaction(db string, fun func() error) (e error)
- type Cache
- type Driver
- type DriverType
- type Fielder
- type Ormer
- type Params
- type ParamsList
- type QuerySeter
- type RawPreparer
- type RawSeter
- type StrTo
- func (f StrTo) Bool() (bool, error)
- func (f *StrTo) Clear()
- func (f StrTo) Exist() bool
- func (f StrTo) Float32() (float32, error)
- func (f StrTo) Float64() (float64, error)
- func (f StrTo) Int() (int, error)
- func (f StrTo) Int16() (int16, error)
- func (f StrTo) Int32() (int32, error)
- func (f StrTo) Int64() (int64, error)
- func (f StrTo) Int8() (int8, error)
- func (f *StrTo) Set(v string)
- func (f StrTo) String() string
- func (f StrTo) Uint() (uint, error)
- func (f StrTo) Uint16() (uint16, error)
- func (f StrTo) Uint32() (uint32, error)
- func (f StrTo) Uint64() (uint64, error)
- func (f StrTo) Uint8() (uint8, error)
Constants ¶
const ( ColAdd operator = iota ColMinus ColMultiply ColExcept )
define Col operations
const ( TypeBooleanField = 1 << iota TypeCharField TypeTextField TypeTimeField TypeDateField TypeDateTimeField TypeBitField TypeSmallIntegerField TypeIntegerField TypeBigIntegerField TypePositiveBitField TypePositiveSmallIntegerField TypePositiveIntegerField TypePositiveBigIntegerField TypeFloatField TypeDecimalField TypeJSONField TypeJsonbField RelForeignKey RelOneToOne RelManyToMany RelReverseOne RelReverseMany )
const ( IsIntegerField = ^-TypePositiveBigIntegerField >> 5 << 6 IsPositiveIntegerField = ^-TypePositiveBigIntegerField >> 9 << 10 IsRelField = ^-RelReverseMany >> 17 << 18 IsFieldType = ^-RelReverseMany<<1 + 1 )
Define some logic enum
const (
DebugQueries = iota
)
Variables ¶
var ( DefaultRowsLimit = 1000 DefaultRelsDepth = 2 DefaultTimeLoc = time.Local )
Functions ¶
func AddAliasWthDB ¶
AddAliasWthDB add a aliasName for the drivename
func ColValue ¶
func ColValue(opt operator, value interface{}) interface{}
ColValue do the field raw changes. e.g Nums = Nums + 10. usage:
Params{ "Nums": ColValue(Col_Add, 10), }
func GetDB ¶
GetDB Get *sql.DB from registered database by db alias name. Use "default" as alias name if you not set.
func RegisterDataBase ¶
RegisterDataBase Setting the database connect params. Use the database driver this dataSource args.
func RegisterDriver ¶
func RegisterDriver(driverName string, typ DriverType) error
RegisterDriver Register a database driver use specify driver name, this can be definition the driver is which database type.
func ResetModelCache ¶
func ResetModelCache()
ResetModelCache Clean model cache. Then you can re-RegModel. Common use this api for test case.
func SetConnMaxLifetime ¶
SetConnMaxLifetime
func SetDataBaseTZ ¶
SetDataBaseTZ Change the database default used timezone
func SetMaxIdleConns ¶
SetMaxIdleConns Change the max idle conns for *sql.DB, use specify database alias name
func SetMaxOpenConns ¶
SetMaxOpenConns Change the max open conns for *sql.DB, use specify database alias name
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is Redis cache adapter.
type Driver ¶
type Driver interface { Name() string Type() DriverType }
Driver define database driver
type DriverType ¶
type DriverType int
DriverType database driver constant int.
const ( DRMySQL DriverType // mysql DRSqlite // sqlite DROracle // oracle DRPostgres // pgsql DRTiDB // TiDB )
Enum the Database driver
type Fielder ¶
type Fielder interface { String() string FieldType() int SetRaw(interface{}) error RawValue() interface{} }
Fielder define field info
type Ormer ¶
type Ormer interface { // switch to another registered database driver by given name. Using(name string) error Begin() error Commit() error Rollback() error Raw(query string, args ...interface{}) RawSeter RawCallBack(func(string, []interface{})) Driver() Driver }
Ormer define the orm interface
type QuerySeter ¶
type QuerySeter interface { }
type RawPreparer ¶
RawPreparer raw query statement