gorm

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGormSession

func NewGormSession() repository.DbSession

Types

type GormSession

type GormSession struct {
	Session *gorm.DB
}

func (*GormSession) Begin

func (this *GormSession) Begin() error

func (*GormSession) Close

func (this *GormSession) Close() error

func (*GormSession) Commit

func (this *GormSession) Commit() error

func (*GormSession) Complex

func (this *GormSession) Complex(qb *repository.QueryBuilder, dest []interface{}) error

func (*GormSession) Count

func (this *GormSession) Count(bean interface{}, conds string, params ...interface{}) (int64, error)

func (*GormSession) Delete

func (this *GormSession) Delete(md interface{}, conds string, params ...interface{}) (int64, error)

第一个参数是删除的数据数组,当传入的为结构体指针时,非空和0的field会被作为删除的条件 不支持指定this.Session.Table(new(User))来指定表名,而是通过结构数组来指定,因此不支持map删除 在数据没有Id的时候,使用第二个参数作为条件

func (*GormSession) Exec

func (this *GormSession) Exec(clause string, params ...interface{}) (sql.Result, error)

execute sql and get result

func (*GormSession) Find

func (this *GormSession) Find(rowsSlicePtr interface{}, md interface{}, orderby string, from int, limit int, conds string, params ...interface{}) error

Find retrieve records from table, condiBeans's non-empty fields are conditions. beans could be []Struct, []*Struct, map[int64]Struct map[int64]*Struct everyone := make([]Userinfo, 0) err := engine.Find(&everyone)

func (*GormSession) Get

func (this *GormSession) Get(dest interface{}, locked bool, orderby string, conds string, params ...interface{}) (bool, error)

Get retrieve one record from database, bean's non-empty fields will be as conditions

func (*GormSession) Insert

func (this *GormSession) Insert(mds ...interface{}) (int64, error)

insert model data to database

func (*GormSession) Query

func (this *GormSession) Query(clause string, params ...interface{}) ([]map[string][]byte, error)

execute sql and get result

func (*GormSession) Rollback

func (this *GormSession) Rollback() error

func (*GormSession) Scan

func (this *GormSession) Scan(dest interface{}) (*GormSession, error)

scan result

func (*GormSession) Sync

func (this *GormSession) Sync(bean ...interface{}) error

func (*GormSession) Transaction

func (this *GormSession) Transaction(fc func(s repository.DbSession) error) error

*

	Transaction 的 f 参数类型为 一个在事务内处理的函数
    因此可以将 f 函数作为参数传入 Transaction 函数中。
    return Transaction(func(s *GormSession) error {
        if _,error := session.Insert(User{ID:5,Version:"abc"}); error != nil{
            return error
        }
	})

func (*GormSession) Update

func (this *GormSession) Update(md interface{}, columns []string, conds string, params ...interface{}) (int64, error)

第一个参数是更新的数据数组,当传入的为结构体指针时,只有非空和0的field才会被作为更新的字段 第二个参数指定要被更新的字段名称,即使非空和0的field也会被更新 不支持指定this.Session.Table(new(User))来指定表名,而是通过结构数组来指定,因此不支持map更新 在数据没有Id的时候,使用第三个参数条件bean作为条件

Jump to

Keyboard shortcuts

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