internal

package
v0.0.0-...-c6615d0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// User is globally public accessible object for table user operations.
	User = &UserDao{
		M:     g.DB("default").Table("user").Safe(),
		Table: "user",
		Columns: userColumns{
			Id:       "id",
			Passport: "passport",
			Password: "password",
			Nickname: "nickname",
			CreateAt: "create_at",
			UpdateAt: "update_at",
		},
	}
)

Functions

This section is empty.

Types

type UserDao

type UserDao struct {
	gmvc.M
	Table   string
	Columns userColumns
}

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

func (*UserDao) All

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

All does "SELECT FROM ..." statement for the model. It retrieves the records from table and returns the result as []*model.User. 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 (*UserDao) And

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

And adds "AND" condition to the where statement.

func (*UserDao) Args

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

Args sets custom arguments for model operation.

func (*UserDao) As

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

As sets an alias name for current table.

func (*UserDao) Batch

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

Batch sets the batch operation number for the model.

func (*UserDao) Cache

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

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 (*UserDao) Chunk

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

Chunk iterates the table with given size and callback function.

func (*UserDao) Ctx

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

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 (*UserDao) Data

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

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 (*UserDao) Fields

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

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 (*UserDao) FieldsEx

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

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 (*UserDao) Filter

func (d *UserDao) Filter() *UserDao

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

func (*UserDao) FindAll

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

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

func (*UserDao) FindOne

func (d *UserDao) FindOne(where ...interface{}) (*model.User, error)

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

func (*UserDao) Group

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

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

func (*UserDao) InnerJoin

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

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 (*UserDao) LeftJoin

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

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 (*UserDao) Limit

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

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 (*UserDao) LockShared

func (d *UserDao) LockShared() *UserDao

LockShared sets the lock in share mode for current operation.

func (*UserDao) LockUpdate

func (d *UserDao) LockUpdate() *UserDao

LockUpdate sets the lock for update for current operation.

func (*UserDao) Master

func (d *UserDao) Master() *UserDao

Master marks the following operation on master node.

func (*UserDao) Offset

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

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

func (*UserDao) OmitEmpty

func (d *UserDao) OmitEmpty() *UserDao

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

func (*UserDao) One

func (d *UserDao) One(where ...interface{}) (*model.User, error)

One retrieves one record from table and returns the result as *model.User. 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 (*UserDao) Option

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

Option sets the extra operation option for the model.

func (*UserDao) Or

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

Or adds "OR" condition to the where statement.

func (*UserDao) Order

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

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

func (*UserDao) Page

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

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 (*UserDao) RightJoin

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

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 (*UserDao) Slave

func (d *UserDao) Slave() *UserDao

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

func (*UserDao) TX

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

TX sets the transaction for current operation.

func (*UserDao) Unscoped

func (d *UserDao) Unscoped() *UserDao

Unscoped enables/disables the soft deleting feature.

func (*UserDao) Where

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

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 (*UserDao) WherePri

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

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