GoFrame 鏈?zhǔn)讲僮?基本介紹

2022-04-02 12:01 更新

?gdb?鏈?zhǔn)讲僮魇褂梅绞胶唵戊`活,是?GoFrame?框架官方推薦的數(shù)據(jù)庫操作方式。鏈?zhǔn)讲僮骺梢酝ㄟ^數(shù)據(jù)庫對象的?db.Model?方法或者事務(wù)對象的?tx.Model?方法,基于指定的數(shù)據(jù)表返回一個鏈?zhǔn)讲僮鲗ο?*Model?,該對象可以執(zhí)行以下方法。當(dāng)前方法列表可能滯后于源代碼,詳細(xì)的方法列表請參考接口文檔: https://pkg.go.dev/github.com/gogf/gf/v2/database/gdb#Model

// 寫入/更新/刪除基本操作
func (m *Model) Insert(data ...interface{}) (result sql.Result, err error)
func (m *Model) InsertAndGetId(data ...interface{}) (lastInsertId int64, err error)
func (m *Model) InsertIgnore(data ...interface{}) (result sql.Result, err error)
func (m *Model) Replace(data ...interface{}) (result sql.Result, err error)
func (m *Model) Save(data ...interface{}) (result sql.Result, err error)
func (m *Model) Update(dataAndWhere ...interface{}) (result sql.Result, err error)
func (m *Model) Delete(where ...interface{}) (result sql.Result, err error)

// 基本查詢操作
func (m *Model) All(where ...interface{} (Result, error)
func (m *Model) One(where ...interface{}) (Record, error)
func (m *Model) Array(fieldsAndWhere ...interface{}) ([]Value, error)
func (m *Model) Value(fieldsAndWhere ...interface{}) (Value, error)
func (m *Model) Count(where ...interface{}) (int, error)
func (m *Model) CountColumn(column string) (int, error)

// 常用基本統(tǒng)計
func (m *Model) Min(column string) (float64, error)
func (m *Model) Max(column string) (float64, error)
func (m *Model) Avg(column string) (float64, error)
func (m *Model) Sum(column string) (float64, error)

// 字段自增/自減
func (m *Model) Increment(column string, amount float64) (sql.Result, error)
func (m *Model) Decrement(column string, amount float64) (sql.Result, error)

// 主鍵查詢操作
func (m *Model) FindAll(where ...interface{}) (Result, error)
func (m *Model) FindOne(where ...interface{}) (Record, error)
func (m *Model) FindArray(fieldsAndWhere ...interface{}) (Value, error)
func (m *Model) FindValue(fieldsAndWhere ...interface{}) (Value, error)
func (m *Model) FindCount(where ...interface{}) (int, error)
func (m *Model) FindScan(pointer interface{}, where ...interface{}) error

// 查詢轉(zhuǎn)換操作
func (m *Model) Struct(pointer interface{}) error
func (m *Model) Structs(pointer interface{}) error
func (m *Model) Scan(pointer interface{}) error
func (m *Model) ScanList(listPointer interface{}, attributeName string, relation ...string) (err error)

// 聯(lián)表查詢方法
func (m *Model) LeftJoin(table ...string) *Model
func (m *Model) RightJoin(table ...string) *Model
func (m *Model) InnerJoin(table ...string) *Model

// 聯(lián)合查詢
func (m *Model) Union(unions ...*Model) *Model
func (m *Model) UnionAll(unions ...*Model) *Model

// With關(guān)聯(lián)查詢
func (m *Model) With(object interface{}) *Model
func (m *Model) WithAll() *Model

// 條件查詢方法 
func (m *Model) Where(where interface{}, args...interface{}) *Model
func (m *Model) WherePri(where interface{}, args ...interface{}) *Model
func (m *Model) WhereBetween(column string, min, max interface{}) *Model
func (m *Model) WhereLike(column string, like interface{}) *Model
func (m *Model) WhereIn(column string, in interface{}) *Model
func (m *Model) WhereNull(columns ...string) *Model
func (m *Model) WhereLT(column string, value interface{}) *Model
func (m *Model) WhereLTE(column string, value interface{}) *Model
func (m *Model) WhereGT(column string, value interface{}) *Model
func (m *Model) WhereGTE(column string, value interface{}) *Model

func (m *Model) WhereNotBetween(column string, min, max interface{}) *Model
func (m *Model) WhereNotLike(column string, like interface{}) *Model
func (m *Model) WhereNotIn(column string, in interface{}) *Model
func (m *Model) WhereNotNull(columns ...string) *Model

func (m *Model) WhereOr(where interface{}, args ...interface{}) *Model
func (m *Model) WhereOrBetween(column string, min, max interface{}) *Model
func (m *Model) WhereOrLike(column string, like interface{}) *Model
func (m *Model) WhereOrIn(column string, in interface{}) *Model
func (m *Model) WhereOrNull(columns ...string) *Model
func (m *Model) WhereOrLT(column string, value interface{}) *Model 
func (m *Model) WhereOrLTE(column string, value interface{}) *Model 
func (m *Model) WhereOrGT(column string, value interface{}) *Model 
func (m *Model) WhereOrGTE(column string, value interface{}) *Model

func (m *Model) WhereOrNotBetween(column string, min, max interface{}) *Model
func (m *Model) WhereOrNotLike(column string, like interface{}) *Model
func (m *Model) WhereOrNotIn(column string, in interface{}) *Model
func (m *Model) WhereOrNotNull(columns ...string) *Model

// 分組排序方法
func (m *Model) Group(group string) *Model
func (m *Model) Order(order string) *Model
func (m *Model) OrderAsc(column string) *Model
func (m *Model) OrderDesc(column string) *Model
func (m *Model) OrderRandom() *Model

// 條件過濾方法
func (m *Model) Fields(fields string) *Model
func (m *Model) FieldsEx(fields string) *Model
func (m *Model) Data(data...interface{}) *Model
func (m *Model) Batch(batch int) *Model
func (m *Model) Filter() *Model
func (m *Model) Safe(safe...bool) *Model
func (m *Model) Having(having interface{}, args ...interface{}) *Model
func (m *Model) Offset(offset int) *Model
func (m *Model) Limit(start int, limit int) *Model
func (m *Model) OmitEmpty() *Model
func (m *Model) Page(page, limit int) (*Model)
func (m *Model) Distinct() *Model

// 數(shù)據(jù)庫/事務(wù)切換
func (m *Model) DB(db DB) *Model
func (m *Model) TX(tx *TX) *Model

// 主從自定義切換
func (m *Model) Master() *Model
func (m *Model) Slave() *Model

// 數(shù)據(jù)互斥鎖操作
func (m *Model) LockUpdate() *Model
func (m *Model) LockShared() *Model

// 常用工具方法
func (m *Model) Ctx(ctx context.Context) *Model
func (m *Model) Clone() *Model
func (m *Model) Cache(duration time.Duration, name ...string) *Model 
func (m *Model) As(as string) *Model
func (m *Model) Chunk(limit int, callback func(result Result, err error) bool)
func (m *Model) Schema(schema string) *Model
func (m *Model) Option(option int) *Model
func (m *Model) Args(args ...interface{}) *Model
func (m *Model) Unscoped() *Model
func (m *Model) HasField(field string) (bool, error)
func (m *Model) GetFieldsStr(prefix ...string) string
func (m *Model) GetFieldsExStr(fields string, prefix ...string) string


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號