model

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColAdd operator = iota
	ColMinus
	ColMultiply
	ColExcept
)

define Col operations

View Source
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
)
View Source
const (
	IsIntegerField         = ^-TypePositiveBigIntegerField >> 5 << 6
	IsPositiveIntegerField = ^-TypePositiveBigIntegerField >> 9 << 10
	IsRelField             = ^-RelReverseMany >> 17 << 18
	IsFieldType            = ^-RelReverseMany<<1 + 1
)

Define some logic enum

View Source
const (
	DebugQueries = iota
)

Variables

View Source
var (
	DefaultRowsLimit = 1000
	DefaultRelsDepth = 2
	DefaultTimeLoc   = time.Local
)

Functions

func AddAliasWthDB

func AddAliasWthDB(aliasName, driverName string, db *sql.DB) error

AddAliasWthDB add a aliasName for the drivename

func AddDatabase

func AddDatabase(name string, c *Cache)

AddDatabase 加入 枚举库 enum/db 和缓存

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 Do

func Do(name, cmd string, to ...interface{}) (reply interface{}, err error)

func GetConnects

func GetConnects(name string) int

GetConnects 获取连接数

func GetDB

func GetDB(aliasNames ...string) (*sql.DB, error)

GetDB Get *sql.DB from registered database by db alias name. Use "default" as alias name if you not set.

func RegisterDataBase

func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) error

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

func SetConnMaxLifetime(aliasName string, connMaxLifetime int)

SetConnMaxLifetime

func SetDataBaseTZ

func SetDataBaseTZ(aliasName string, tz *time.Location) error

SetDataBaseTZ Change the database default used timezone

func SetMaxIdleConns

func SetMaxIdleConns(aliasName string, maxIdleConns int)

SetMaxIdleConns Change the max idle conns for *sql.DB, use specify database alias name

func SetMaxOpenConns

func SetMaxOpenConns(aliasName string, maxOpenConns int)

SetMaxOpenConns Change the max open conns for *sql.DB, use specify database alias name

func ToInt64

func ToInt64(value interface{}) (d int64)

ToInt64 interface to int64

func ToStr

func ToStr(value interface{}, args ...int) (s string)

ToStr interface to string

func Transaction

func Transaction(db string, fun func() error) (e error)

Transaction 事务执行回调函数

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is Redis cache adapter.

func GetClient

func GetClient(name string) *Cache

GetClient 通过枚举读取client

func NewCache

func NewCache(connection string, password string, dbNum int, idle int, maxOpen int) (cache *Cache, err error)

NewCache 创建新的 Redis Cache 对象。 connection - Redis服务器和端口号,例如: "127.0.0.1:6379", dbNum - Redis 数据库序号

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

func New

func New(db string) (resultOrm Ormer)

New 获取orm

type Params

type Params map[string]interface{}

Params stores the Params

type ParamsList

type ParamsList []interface{}

ParamsList stores paramslist

type QuerySeter

type QuerySeter interface {
}

type RawPreparer

type RawPreparer interface {
	Exec(...interface{}) (sql.Result, error)
	Close() error
}

RawPreparer raw query statement

type RawSeter

type RawSeter interface {
	Exec() (sql.Result, error)
	QueryRow(containers ...interface{}) error
	QueryRows(containers ...interface{}) (int64, error)
	Prepare() (RawPreparer, error)
	RelateCache(...interface{}) RawSeter
}

type StrTo

type StrTo string

StrTo is the target string

func (StrTo) Bool

func (f StrTo) Bool() (bool, error)

Bool string to bool

func (*StrTo) Clear

func (f *StrTo) Clear()

Clear string

func (StrTo) Exist

func (f StrTo) Exist() bool

Exist check string exist

func (StrTo) Float32

func (f StrTo) Float32() (float32, error)

Float32 string to float32

func (StrTo) Float64

func (f StrTo) Float64() (float64, error)

Float64 string to float64

func (StrTo) Int

func (f StrTo) Int() (int, error)

Int string to int

func (StrTo) Int16

func (f StrTo) Int16() (int16, error)

Int16 string to int16

func (StrTo) Int32

func (f StrTo) Int32() (int32, error)

Int32 string to int32

func (StrTo) Int64

func (f StrTo) Int64() (int64, error)

Int64 string to int64

func (StrTo) Int8

func (f StrTo) Int8() (int8, error)

Int8 string to int8

func (*StrTo) Set

func (f *StrTo) Set(v string)

Set string

func (StrTo) String

func (f StrTo) String() string

String string to string

func (StrTo) Uint

func (f StrTo) Uint() (uint, error)

Uint string to uint

func (StrTo) Uint16

func (f StrTo) Uint16() (uint16, error)

Uint16 string to uint16

func (StrTo) Uint32

func (f StrTo) Uint32() (uint32, error)

Uint32 string to uint31

func (StrTo) Uint64

func (f StrTo) Uint64() (uint64, error)

Uint64 string to uint64

func (StrTo) Uint8

func (f StrTo) Uint8() (uint8, error)

Uint8 string to uint8

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL