internal

package
v0.0.0-...-92a1e37 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Guser is globally public accessible object for table guser operations.
	Guser = GuserDao{
		M:     g.DB("default").Model("guser").Safe(),
		DB:    g.DB("default"),
		Table: "guser",
		Columns: guserColumns{
			Id:         "id",
			Account:    "account",
			Password:   "password",
			CreateTime: "create_time",
		},
	}
)

Functions

This section is empty.

Types

type GuserDao

type GuserDao struct {
	gmvc.M
	DB      gdb.DB
	Table   string
	Columns guserColumns
}

GuserDao is the manager for logic model data accessing and custom defined data operations functions management.

func (*GuserDao) All

func (d *GuserDao) All(where ...interface{}) ([]*model.Guser, error)

All does "SELECT FROM ..." statement for the model. It retrieves the records from table and returns the result as []*model.Guser. It returns nil if there's no record retrieved with the given conditions from table.

The optional parameter <where> is the same as the parameter of M.Where function, see M.Where.

func (*GuserDao) And

func (d *GuserDao) And(where interface{}, args ...interface{}) *GuserDao

And adds "AND" condition to the where statement.

func (*GuserDao) Args

func (d *GuserDao) Args(args ...interface{}) *GuserDao

Args sets custom arguments for model operation.

func (*GuserDao) As

func (d *GuserDao) As(as string) *GuserDao

As sets an alias name for current table.

func (*GuserDao) Batch

func (d *GuserDao) Batch(batch int) *GuserDao

Batch sets the batch operation number for the model.

func (*GuserDao) Cache

func (d *GuserDao) Cache(duration time.Duration, name ...string) *GuserDao

Cache sets the cache feature for the model. It caches the result of the sql, which means if there's another same sql request, it just reads and returns the result from cache, it but not committed and executed into the database.

If the parameter <duration> < 0, which means it clear the cache with given <name>. If the parameter <duration> = 0, which means it never expires. If the parameter <duration> > 0, which means it expires after <duration>.

The optional parameter <name> is used to bind a name to the cache, which means you can later control the cache like changing the <duration> or clearing the cache with specified <name>.

Note that, the cache feature is disabled if the model is operating on a transaction.

func (*GuserDao) Chunk

func (d *GuserDao) Chunk(limit int, callback func(entities []*model.Guser, err error) bool)

Chunk iterates the table with given size and callback function.

func (*GuserDao) Ctx

func (d *GuserDao) Ctx(ctx context.Context) *GuserDao

Ctx is a chaining function, which creates and returns a new DB that is a shallow copy of current DB object and with given context in it. Note that this returned DB object can be used only once, so do not assign it to a global or package variable for long using.

func (*GuserDao) Data

func (d *GuserDao) Data(data ...interface{}) *GuserDao

Data sets the operation data for the model. The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc. Eg: Data("uid=10000") Data("uid", 10000) Data(g.Map{"uid": 10000, "name":"john"}) Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})

func (*GuserDao) Fields

func (d *GuserDao) Fields(fieldNamesOrMapStruct ...interface{}) *GuserDao

Fields sets the operation fields of the model, multiple fields joined using char ','. The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.

func (*GuserDao) FieldsEx

func (d *GuserDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *GuserDao

FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','. The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.

func (*GuserDao) Filter

func (d *GuserDao) Filter() *GuserDao

Filter marks filtering the fields which does not exist in the fields of the operated table.

func (*GuserDao) FindAll

func (d *GuserDao) FindAll(where ...interface{}) ([]*model.Guser, error)

FindAll retrieves and returns Result by by M.WherePri and M.All. Also see M.WherePri and M.All.

func (*GuserDao) FindOne

func (d *GuserDao) FindOne(where ...interface{}) (*model.Guser, error)

FindOne retrieves and returns a single Record by M.WherePri and M.One. Also see M.WherePri and M.One.

func (*GuserDao) Group

func (d *GuserDao) Group(groupBy string) *GuserDao

Group sets the "GROUP BY" statement for the model.

func (*GuserDao) InnerJoin

func (d *GuserDao) InnerJoin(table ...string) *GuserDao

InnerJoin does "INNER JOIN ... ON ..." statement on the model. The parameter <table> can be joined table and its joined condition, and also with its alias name, like: Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")

func (*GuserDao) LeftJoin

func (d *GuserDao) LeftJoin(table ...string) *GuserDao

LeftJoin does "LEFT JOIN ... ON ..." statement on the model. The parameter <table> can be joined table and its joined condition, and also with its alias name, like: Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")

func (*GuserDao) Limit

func (d *GuserDao) Limit(limit ...int) *GuserDao

Limit sets the "LIMIT" statement for the model. The parameter <limit> can be either one or two number, if passed two number is passed, it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]" statement.

func (*GuserDao) LockShared

func (d *GuserDao) LockShared() *GuserDao

LockShared sets the lock in share mode for current operation.

func (*GuserDao) LockUpdate

func (d *GuserDao) LockUpdate() *GuserDao

LockUpdate sets the lock for update for current operation.

func (*GuserDao) Master

func (d *GuserDao) Master() *GuserDao

Master marks the following operation on master node.

func (*GuserDao) Offset

func (d *GuserDao) Offset(offset int) *GuserDao

Offset sets the "OFFSET" statement for the model. It only makes sense for some databases like SQLServer, PostgreSQL, etc.

func (*GuserDao) OmitEmpty

func (d *GuserDao) OmitEmpty() *GuserDao

OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers the data and where attributes for empty values.

func (*GuserDao) One

func (d *GuserDao) One(where ...interface{}) (*model.Guser, error)

One retrieves one record from table and returns the result as *model.Guser. It returns nil if there's no record retrieved with the given conditions from table.

The optional parameter <where> is the same as the parameter of M.Where function, see M.Where.

func (*GuserDao) Option

func (d *GuserDao) Option(option int) *GuserDao

Option sets the extra operation option for the model.

func (*GuserDao) Or

func (d *GuserDao) Or(where interface{}, args ...interface{}) *GuserDao

Or adds "OR" condition to the where statement.

func (*GuserDao) Order

func (d *GuserDao) Order(orderBy ...string) *GuserDao

Order sets the "ORDER BY" statement for the model.

func (*GuserDao) Page

func (d *GuserDao) Page(page, limit int) *GuserDao

Page sets the paging number for the model. The parameter <page> is started from 1 for paging. Note that, it differs that the Limit function start from 0 for "LIMIT" statement.

func (*GuserDao) RightJoin

func (d *GuserDao) RightJoin(table ...string) *GuserDao

RightJoin does "RIGHT JOIN ... ON ..." statement on the model. The parameter <table> can be joined table and its joined condition, and also with its alias name, like: Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")

func (*GuserDao) Scan

func (d *GuserDao) Scan(pointer interface{}, where ...interface{}) error

Scan automatically calls Struct or Structs function according to the type of parameter <pointer>. It calls function Struct if <pointer> is type of *struct/**struct. It calls function Structs if <pointer> is type of *[]struct/*[]*struct.

The optional parameter <where> is the same as the parameter of Model.Where function, see Model.Where.

Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.

Eg: user := new(User) err := dao.User.Where("id", 1).Scan(user)

user := (*User)(nil) err := dao.User.Where("id", 1).Scan(&user)

users := ([]User)(nil) err := dao.User.Scan(&users)

users := ([]*User)(nil) err := dao.User.Scan(&users)

func (*GuserDao) Slave

func (d *GuserDao) Slave() *GuserDao

Slave marks the following operation on slave node. Note that it makes sense only if there's any slave node configured.

func (*GuserDao) Struct

func (d *GuserDao) Struct(pointer interface{}, where ...interface{}) error

Struct retrieves one record from table and converts it into given struct. The parameter <pointer> should be type of *struct/**struct. If type **struct is given, it can create the struct internally during converting.

The optional parameter <where> is the same as the parameter of Model.Where function, see Model.Where.

Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions from table and <pointer> is not nil.

Eg: user := new(User) err := dao.User.Where("id", 1).Struct(user)

user := (*User)(nil) err := dao.User.Where("id", 1).Struct(&user)

func (*GuserDao) Structs

func (d *GuserDao) Structs(pointer interface{}, where ...interface{}) error

Structs retrieves records from table and converts them into given struct slice. The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct slice internally during converting.

The optional parameter <where> is the same as the parameter of Model.Where function, see Model.Where.

Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions from table and <pointer> is not empty.

Eg: users := ([]User)(nil) err := dao.User.Structs(&users)

users := ([]*User)(nil) err := dao.User.Structs(&users)

func (*GuserDao) TX

func (d *GuserDao) TX(tx *gdb.TX) *GuserDao

TX sets the transaction for current operation.

func (*GuserDao) Unscoped

func (d *GuserDao) Unscoped() *GuserDao

Unscoped enables/disables the soft deleting feature.

func (*GuserDao) Where

func (d *GuserDao) Where(where interface{}, args ...interface{}) *GuserDao

Where sets the condition statement for the model. The parameter <where> can be type of string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times, multiple conditions will be joined into where statement using "AND". Eg: Where("uid=10000") Where("uid", 10000) Where("money>? AND name like ?", 99999, "vip_%") Where("uid", 1).Where("name", "john") Where("status IN (?)", g.Slice{1,2,3}) Where("age IN(?,?)", 18, 50) Where(User{ Id : 1, UserName : "john"})

func (*GuserDao) WherePri

func (d *GuserDao) WherePri(where interface{}, args ...interface{}) *GuserDao

WherePri does the same logic as M.Where except that if the parameter <where> is a single condition like int/string/float/slice, it treats the condition as the primary key value. That is, if primary key is "id" and given <where> parameter as "123", the WherePri function treats the condition as "id=123", but M.Where treats the condition as string "123".

Jump to

Keyboard shortcuts

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