Documentation ¶
Index ¶
- Constants
- Variables
- func BetweenTime(v nonSupportBetweenTime)
- func GetUUID32(uuid string) string
- func GetUUID36(uuid32 string) string
- func ResetAndMock(db Database, mock Mock)
- func UUID() string
- type AND
- type Alter
- type CUDIDList
- type CUDInfo
- type CreateTableInfo
- type DataSourceName
- type Database
- func (database Database) Close()
- func (db *Database) CountQB(modelPtr Model, qb QB) (count int)
- func (db *Database) Create(modelPtr Model)
- func (db *Database) Delete(modelPtr Model)
- func (db *Database) DeleteQB(modelPtr Model, qb QB)
- func (database Database) GetDataSourceName() DataSourceName
- func (db *Database) ListQB(modelListPtr interface{}, qb QB)
- func (db *Database) OneID(modelPtr Model, has *bool, id interface{})
- func (db *Database) OneQB(modelPtr Model, has *bool, qb QB)
- func (db Database) ReadQB(conf ReadQB)
- func (db Database) Tx() *Tx
- func (db *Database) TxCountQB(tx *Tx, modelPtr Model, qb QB) (count int)
- func (db *Database) TxCreate(tx *Tx, modelPtr Model)
- func (db *Database) TxDelete(tx *Tx, modelPtr Model, qb QB)
- func (db *Database) TxDeleteQB(tx *Tx, modelPtr Model, qb QB)
- func (db *Database) TxListQB(tx *Tx, modelListPtr []Model, qb QB)
- func (db *Database) TxOneID(tx *Tx, modelPtr Model, has *bool, id interface{})
- func (db *Database) TxOneQB(tx *Tx, modelPtr Model, has *bool, qb QB)
- func (db *Database) TxUpdate(tx *Tx, modelPtr Model)
- func (db *Database) Update(modelPtr Model)
- type Filter
- func BetweenFloat(begin float64, end float64) Filter
- func BetweenInt(begin int, end int) Filter
- func BetweenString(begin string, end string) Filter
- func Custom(template string, v ...interface{}) Filter
- func CustomSQL(sql string, values ...interface{}) Filter
- func Day(v time.Time) Filter
- func Eql(v interface{}) Filter
- func Gt(v interface{}) Filter
- func GtEql(v interface{}) Filter
- func Ignore(filter Filter, ignoreCondition bool) Filter
- func IgnoreEmpty(filterFunc FilterFunc, query string) Filter
- func IgnoreFilter() Filter
- func IgnorePattern(filterFunc FilterFunc, query string, pattern string) Filter
- func In(v interface{}) Filter
- func IsNotNull() Filter
- func IsNull() Filter
- func Like(v interface{}) Filter
- func LikeEnd(v interface{}) Filter
- func LikeStart(v interface{}) Filter
- func Lt(v interface{}) Filter
- func LtEql(v interface{}) Filter
- func NotEql(v interface{}) Filter
- func NotIn(v interface{}) Filter
- func TimeRange(data gtime.Range, sqlValueLayout string) Filter
- type FilterFunc
- type FilterTimeRange
- type Group
- type Map
- type Migrate
- func (Migrate) AlterTable(tableName string) Alter
- func (mi Migrate) CUDTimestamp() []MigrateField
- func (Migrate) CreateTable(info CreateTableInfo)
- func (mi Migrate) CreatedAtTimestamp() MigrateField
- func (mi Migrate) CurrentTimeStamp() migrateDefaultValue
- func (mi Migrate) DefaultString(s string) migrateDefaultValue
- func (mi Migrate) DeletedAtTimestamp() MigrateField
- func (Migrate) Field(name string) MigrateField
- func (mi Migrate) Init(db Database)
- func (mi Migrate) InnoDB() string
- func (Migrate) MigrateName(name string)
- func (mi Migrate) UpdatedAtTimestamp() MigrateField
- func (mi Migrate) Utf8mb4() string
- func (mi Migrate) Utf8mb4_unicode_ci() string
- type MigrateField
- func (mi MigrateField) AutoIncrement() MigrateField
- func (mi MigrateField) Collate(kind string) MigrateField
- func (mi MigrateField) Commit(commit string) MigrateField
- func (mi MigrateField) Default(value migrateDefaultValue) MigrateField
- func (mi MigrateField) Extra(extra string) MigrateField
- func (mi MigrateField) Int(size int) MigrateField
- func (mi MigrateField) Null() MigrateField
- func (mi MigrateField) OnUpdateCurrentTimeStamp() MigrateField
- func (mi MigrateField) PrimaryKey(field string) MigrateField
- func (mi MigrateField) Text() MigrateField
- func (mi MigrateField) Timestamp() MigrateField
- func (mi MigrateField) Tinyint(size int) MigrateField
- func (mi MigrateField) Unsigned() MigrateField
- func (mi MigrateField) Varchar(size int) MigrateField
- type MigrateModel
- type Mock
- type Model
- type NotesReadQBType
- type OP
- type Order
- type QB
- func (qb QB) BindModel(model interface{}) QB
- func (qb QB) GetInsert() (sql string, sqlValues []interface{})
- func (qb QB) GetSelect() (sql string, sqlValues []interface{})
- func (qb QB) GetUpdate() (sql string, sqlValues []interface{})
- func (qb QB) Paging(page int, perPage int) QB
- func (qb QB) SQL(props SQLProps) (sql string, sqlValues []interface{})
- type ReadQB
- type SQLProps
- type Tx
Constants ¶
View Source
const ( DESC orderType = iota ASC )
Variables ¶
View Source
var NotesReadQB = NotesReadQBType{
Message: `
请确保基于 f.QB 的查询结果不可变,或者基于时间倒叙查询。(从最早的数据查询到最新的数据)
目的是为了避免查询数据过程中有新的数据插入,此时 ReadQB 内部通过 offset 查询时会不准确。
`,
}
Functions ¶
func BetweenTime ¶
func BetweenTime(v nonSupportBetweenTime)
you can use f.TimeRange, not BetweenTime
func ResetAndMock ¶
Types ¶
type AND ¶
QueryBuilder Where
type Alter ¶
type Alter struct {
// contains filtered or unexported fields
}
func (Alter) Modify ¶
func (al Alter) Modify(migrateField MigrateField) Alter
type CreateTableInfo ¶
type CreateTableInfo struct { TableName string Fields []MigrateField Engine string DefaultCharset string Collate string }
type DataSourceName ¶
type DataSourceName struct { DriverName string User string Password string Host string Port string DB string Query map[string]string }
DataSourceName.User 是个 map[string]stirng 结构 用于生成 dataSourceName 中的 ?charset=utf8&parseTime=True&loc=Local 部分
func (DataSourceName) GetString ¶
func (config DataSourceName) GetString() (dataSourceName string)
type Database ¶
func NewDatabase ¶
func NewDatabase(dataSourceName DataSourceName) (database Database)
func (Database) GetDataSourceName ¶
func (database Database) GetDataSourceName() DataSourceName
type Filter ¶
type Filter struct { FieldWrap string FieldWarpArg string Value interface{} Kind string Symbol string Like string Custom string CustomSQL string TimeValue time.Time TimeRange FilterTimeRange BetweenInt struct { Begin int End int } BetweenFloat struct { Begin float64 End float64 } BetweenString struct { Begin string End string } }
func BetweenFloat ¶
func BetweenInt ¶
func BetweenString ¶
func Ignore ¶
在 IgnoreEmpty 和 IgnorePattern 的场景下WHERE 语句都是 field = ? 有些场景下可能需要 where field in ? 或者没有 field in ? 此时使用 Ignore 完全自定义控制
使用场景: f.QB{ Where: f.And( "id": f.Ignore(len(query.idList) == 0, f.In(query.idList)) ), }
func IgnoreEmpty ¶
func IgnoreEmpty(filterFunc FilterFunc, query string) Filter
在查询中有一种常见的场景,当某个请求参数为空时不增加 where。 比如用户搜索姓名, ?name=nimo 时SQL是 WHERE name = ? 。 如果 ?name= (空字符串)则 sql 没有 name = ? gofree 称这种 where 条件为 ignore empty
使用场景: f.QB{ Where: f.And( "name": f.IgnoreEmpty(f.Eql, query.Name) ), }
func IgnoreFilter ¶
func IgnoreFilter() Filter
func IgnorePattern ¶
func IgnorePattern(filterFunc FilterFunc, query string, pattern string) Filter
基于 IgnoreEmpty 的场景下,有些请求并不一定会是空,而是 ?status=all 来表示搜索全部 ?status=done 表示搜索已完成的数据 ,此时使用 IgnorePattern(f.Eql, query.Status, "all")
使用场景: f.QB{ Where: f.And( "status": f.IgnorePattern( f.Eql, query.Status, "all") ), }
type FilterFunc ¶
type FilterFunc func(v interface{}) Filter
type FilterTimeRange ¶
type Migrate ¶
type Migrate struct {
// contains filtered or unexported fields
}
func NewMigrate ¶
func (Migrate) AlterTable ¶
func (Migrate) CUDTimestamp ¶
func (mi Migrate) CUDTimestamp() []MigrateField
func (Migrate) CreateTable ¶
func (Migrate) CreateTable(info CreateTableInfo)
func (Migrate) CreatedAtTimestamp ¶
func (mi Migrate) CreatedAtTimestamp() MigrateField
func (Migrate) CurrentTimeStamp ¶
func (mi Migrate) CurrentTimeStamp() migrateDefaultValue
func (Migrate) DefaultString ¶
func (Migrate) DeletedAtTimestamp ¶
func (mi Migrate) DeletedAtTimestamp() MigrateField
func (Migrate) Field ¶
func (Migrate) Field(name string) MigrateField
func (Migrate) MigrateName ¶
func (Migrate) UpdatedAtTimestamp ¶
func (mi Migrate) UpdatedAtTimestamp() MigrateField
func (Migrate) Utf8mb4_unicode_ci ¶
type MigrateField ¶
type MigrateField struct {
// contains filtered or unexported fields
}
func (MigrateField) AutoIncrement ¶
func (mi MigrateField) AutoIncrement() MigrateField
func (MigrateField) Collate ¶
func (mi MigrateField) Collate(kind string) MigrateField
func (MigrateField) Commit ¶
func (mi MigrateField) Commit(commit string) MigrateField
func (MigrateField) Default ¶
func (mi MigrateField) Default(value migrateDefaultValue) MigrateField
func (MigrateField) Extra ¶
func (mi MigrateField) Extra(extra string) MigrateField
func (MigrateField) Int ¶
func (mi MigrateField) Int(size int) MigrateField
func (MigrateField) Null ¶
func (mi MigrateField) Null() MigrateField
func (MigrateField) OnUpdateCurrentTimeStamp ¶
func (mi MigrateField) OnUpdateCurrentTimeStamp() MigrateField
func (MigrateField) PrimaryKey ¶
func (mi MigrateField) PrimaryKey(field string) MigrateField
func (MigrateField) Text ¶
func (mi MigrateField) Text() MigrateField
func (MigrateField) Timestamp ¶
func (mi MigrateField) Timestamp() MigrateField
func (MigrateField) Tinyint ¶
func (mi MigrateField) Tinyint(size int) MigrateField
func (MigrateField) Unsigned ¶
func (mi MigrateField) Unsigned() MigrateField
func (MigrateField) Varchar ¶
func (mi MigrateField) Varchar(size int) MigrateField
type MigrateModel ¶
type NotesReadQBType ¶
type NotesReadQBType struct {
Message string
}
type QB ¶
type QB struct { Table string UseIndex string Select []string Where []AND Offset int Limit int Order []Order Group []string SoftDelete string Insert Map Update Map Count bool Debug bool Check []string }
type ReadQB ¶
type ReadQB struct { Limit int ListPtr interface{} QB QB Read func() Notes NotesReadQBType }
配置项
type SQLProps ¶
type SQLProps struct {
Statement string `eg:"[]string{\"SELECT\", \"UPDATE\", \"DELETE\", \"INSERT\"}"`
}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.