internal

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Contestant is globally public accessible object for table contestant operations.
	Contestant = ContestantDao{
		M:     g.DB("default").Model("contestant").Safe(),
		DB:    g.DB("default"),
		Table: "contestant",
		Columns: contestantColumns{
			Id:        "id",
			Tid:       "tid",
			Name:      "name",
			Vurl:      "vurl",
			Sid:       "sid",
			Score:     "score",
			CreatedAt: "created_at",
			UpdatedAt: "updated_at",
		},
	}
)
View Source
var (
	// Match is globally public accessible object for table match operations.
	Match = MatchDao{
		M:     g.DB("default").Model("match").Safe(),
		DB:    g.DB("default"),
		Table: "match",
		Columns: matchColumns{
			Id:        "id",
			Kvurl:     "kvurl",
			Title:     "title",
			Index:     "index",
			Type:      "type",
			CreatedAt: "created_at",
			UpdatedAt: "updated_at",
		},
	}
)
View Source
var (
	// Rule is globally public accessible object for table rule operations.
	Rule = RuleDao{
		M:     g.DB("default").Model("rule").Safe(),
		DB:    g.DB("default"),
		Table: "rule",
		Columns: ruleColumns{
			Id:        "id",
			Title:     "title",
			Rules:     "rules",
			Desc:      "desc",
			Imgurl:    "imgurl",
			CreatedAt: "created_at",
			UpdatedAt: "updated_at",
		},
	}
)
View Source
var (
	// Score is globally public accessible object for table score operations.
	Score = ScoreDao{
		M:     g.DB("default").Model("score").Safe(),
		DB:    g.DB("default"),
		Table: "score",
		Columns: scoreColumns{
			Uid:       "uid",
			Cid:       "cid",
			Rules:     "rules",
			Score:     "score",
			Comments:  "comments",
			CreatedAt: "created_at",
			UpdatedAt: "updated_at",
		},
	}
)
View Source
var (
	// User is globally public accessible object for table user operations.
	User = UserDao{
		M:     g.DB("default").Model("user").Safe(),
		DB:    g.DB("default"),
		Table: "user",
		Columns: userColumns{
			Id:        "id",
			Name:      "name",
			Password:  "password",
			Desc:      "desc",
			Tid:       "tid",
			Type:      "type",
			Starttime: "starttime",
			Endtime:   "endtime",
			CreatedAt: "created_at",
			UpdatedAt: "updated_at",
		},
	}
)

Functions

This section is empty.

Types

type ContestantDao

type ContestantDao struct {
	gmvc.M
	DB      gdb.DB
	Table   string
	Columns contestantColumns
}

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

func (*ContestantDao) All

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

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

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

And adds "AND" condition to the where statement.

func (*ContestantDao) Args

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

Args sets custom arguments for model operation.

func (*ContestantDao) As

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

As sets an alias name for current table.

func (*ContestantDao) Batch

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

Batch sets the batch operation number for the model.

func (*ContestantDao) Cache

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

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

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

Chunk iterates the table with given size and callback function.

func (*ContestantDao) Ctx

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

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

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

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

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

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

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

func (d *ContestantDao) Filter() *ContestantDao

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

func (*ContestantDao) FindAll

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

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

func (*ContestantDao) FindOne

func (d *ContestantDao) FindOne(where ...interface{}) (*model.Contestant, error)

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

func (*ContestantDao) Group

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

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

func (*ContestantDao) InnerJoin

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

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

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

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

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

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

func (d *ContestantDao) LockShared() *ContestantDao

LockShared sets the lock in share mode for current operation.

func (*ContestantDao) LockUpdate

func (d *ContestantDao) LockUpdate() *ContestantDao

LockUpdate sets the lock for update for current operation.

func (*ContestantDao) Master

func (d *ContestantDao) Master() *ContestantDao

Master marks the following operation on master node.

func (*ContestantDao) Offset

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

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

func (*ContestantDao) OmitEmpty

func (d *ContestantDao) OmitEmpty() *ContestantDao

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

func (*ContestantDao) One

func (d *ContestantDao) One(where ...interface{}) (*model.Contestant, error)

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

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

Option sets the extra operation option for the model.

func (*ContestantDao) Or

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

Or adds "OR" condition to the where statement.

func (*ContestantDao) Order

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

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

func (*ContestantDao) Page

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

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

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

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 (*ContestantDao) Scan

func (d *ContestantDao) 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 (*ContestantDao) Slave

func (d *ContestantDao) Slave() *ContestantDao

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

func (*ContestantDao) Struct

func (d *ContestantDao) 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 (*ContestantDao) Structs

func (d *ContestantDao) 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 (*ContestantDao) TX

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

TX sets the transaction for current operation.

func (*ContestantDao) Unscoped

func (d *ContestantDao) Unscoped() *ContestantDao

Unscoped enables/disables the soft deleting feature.

func (*ContestantDao) Where

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

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

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

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".

type MatchDao

type MatchDao struct {
	gmvc.M
	DB      gdb.DB
	Table   string
	Columns matchColumns
}

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

func (*MatchDao) All

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

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

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

And adds "AND" condition to the where statement.

func (*MatchDao) Args

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

Args sets custom arguments for model operation.

func (*MatchDao) As

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

As sets an alias name for current table.

func (*MatchDao) Batch

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

Batch sets the batch operation number for the model.

func (*MatchDao) Cache

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

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

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

Chunk iterates the table with given size and callback function.

func (*MatchDao) Ctx

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

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

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

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

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

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

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

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

func (d *MatchDao) Filter() *MatchDao

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

func (*MatchDao) FindAll

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

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

func (*MatchDao) FindOne

func (d *MatchDao) FindOne(where ...interface{}) (*model.Match, error)

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

func (*MatchDao) Group

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

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

func (*MatchDao) InnerJoin

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

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

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

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

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

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

func (d *MatchDao) LockShared() *MatchDao

LockShared sets the lock in share mode for current operation.

func (*MatchDao) LockUpdate

func (d *MatchDao) LockUpdate() *MatchDao

LockUpdate sets the lock for update for current operation.

func (*MatchDao) Master

func (d *MatchDao) Master() *MatchDao

Master marks the following operation on master node.

func (*MatchDao) Offset

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

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

func (*MatchDao) OmitEmpty

func (d *MatchDao) OmitEmpty() *MatchDao

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

func (*MatchDao) One

func (d *MatchDao) One(where ...interface{}) (*model.Match, error)

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

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

Option sets the extra operation option for the model.

func (*MatchDao) Or

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

Or adds "OR" condition to the where statement.

func (*MatchDao) Order

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

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

func (*MatchDao) Page

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

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

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

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 (*MatchDao) Scan

func (d *MatchDao) 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 (*MatchDao) Slave

func (d *MatchDao) Slave() *MatchDao

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

func (*MatchDao) Struct

func (d *MatchDao) 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 (*MatchDao) Structs

func (d *MatchDao) 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 (*MatchDao) TX

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

TX sets the transaction for current operation.

func (*MatchDao) Unscoped

func (d *MatchDao) Unscoped() *MatchDao

Unscoped enables/disables the soft deleting feature.

func (*MatchDao) Where

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

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

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

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".

type RuleDao

type RuleDao struct {
	gmvc.M
	DB      gdb.DB
	Table   string
	Columns ruleColumns
}

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

func (*RuleDao) All

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

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

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

And adds "AND" condition to the where statement.

func (*RuleDao) Args

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

Args sets custom arguments for model operation.

func (*RuleDao) As

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

As sets an alias name for current table.

func (*RuleDao) Batch

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

Batch sets the batch operation number for the model.

func (*RuleDao) Cache

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

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

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

Chunk iterates the table with given size and callback function.

func (*RuleDao) Ctx

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

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

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

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

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

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

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

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

func (d *RuleDao) Filter() *RuleDao

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

func (*RuleDao) FindAll

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

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

func (*RuleDao) FindOne

func (d *RuleDao) FindOne(where ...interface{}) (*model.Rule, error)

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

func (*RuleDao) Group

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

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

func (*RuleDao) InnerJoin

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

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

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

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

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

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

func (d *RuleDao) LockShared() *RuleDao

LockShared sets the lock in share mode for current operation.

func (*RuleDao) LockUpdate

func (d *RuleDao) LockUpdate() *RuleDao

LockUpdate sets the lock for update for current operation.

func (*RuleDao) Master

func (d *RuleDao) Master() *RuleDao

Master marks the following operation on master node.

func (*RuleDao) Offset

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

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

func (*RuleDao) OmitEmpty

func (d *RuleDao) OmitEmpty() *RuleDao

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

func (*RuleDao) One

func (d *RuleDao) One(where ...interface{}) (*model.Rule, error)

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

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

Option sets the extra operation option for the model.

func (*RuleDao) Or

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

Or adds "OR" condition to the where statement.

func (*RuleDao) Order

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

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

func (*RuleDao) Page

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

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

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

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 (*RuleDao) Scan

func (d *RuleDao) 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 (*RuleDao) Slave

func (d *RuleDao) Slave() *RuleDao

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

func (*RuleDao) Struct

func (d *RuleDao) 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 (*RuleDao) Structs

func (d *RuleDao) 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 (*RuleDao) TX

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

TX sets the transaction for current operation.

func (*RuleDao) Unscoped

func (d *RuleDao) Unscoped() *RuleDao

Unscoped enables/disables the soft deleting feature.

func (*RuleDao) Where

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

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

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

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".

type ScoreDao

type ScoreDao struct {
	gmvc.M
	DB      gdb.DB
	Table   string
	Columns scoreColumns
}

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

func (*ScoreDao) All

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

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

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

And adds "AND" condition to the where statement.

func (*ScoreDao) Args

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

Args sets custom arguments for model operation.

func (*ScoreDao) As

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

As sets an alias name for current table.

func (*ScoreDao) Batch

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

Batch sets the batch operation number for the model.

func (*ScoreDao) Cache

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

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

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

Chunk iterates the table with given size and callback function.

func (*ScoreDao) Ctx

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

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

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

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

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

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

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

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

func (d *ScoreDao) Filter() *ScoreDao

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

func (*ScoreDao) FindAll

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

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

func (*ScoreDao) FindOne

func (d *ScoreDao) FindOne(where ...interface{}) (*model.Score, error)

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

func (*ScoreDao) Group

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

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

func (*ScoreDao) InnerJoin

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

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

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

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

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

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

func (d *ScoreDao) LockShared() *ScoreDao

LockShared sets the lock in share mode for current operation.

func (*ScoreDao) LockUpdate

func (d *ScoreDao) LockUpdate() *ScoreDao

LockUpdate sets the lock for update for current operation.

func (*ScoreDao) Master

func (d *ScoreDao) Master() *ScoreDao

Master marks the following operation on master node.

func (*ScoreDao) Offset

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

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

func (*ScoreDao) OmitEmpty

func (d *ScoreDao) OmitEmpty() *ScoreDao

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

func (*ScoreDao) One

func (d *ScoreDao) One(where ...interface{}) (*model.Score, error)

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

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

Option sets the extra operation option for the model.

func (*ScoreDao) Or

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

Or adds "OR" condition to the where statement.

func (*ScoreDao) Order

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

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

func (*ScoreDao) Page

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

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

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

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 (*ScoreDao) Scan

func (d *ScoreDao) 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 (*ScoreDao) Slave

func (d *ScoreDao) Slave() *ScoreDao

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

func (*ScoreDao) Struct

func (d *ScoreDao) 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 (*ScoreDao) Structs

func (d *ScoreDao) 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 (*ScoreDao) TX

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

TX sets the transaction for current operation.

func (*ScoreDao) Unscoped

func (d *ScoreDao) Unscoped() *ScoreDao

Unscoped enables/disables the soft deleting feature.

func (*ScoreDao) Where

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

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

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

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".

type UserDao

type UserDao struct {
	gmvc.M
	DB      gdb.DB
	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) Scan

func (d *UserDao) 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 (*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) Struct

func (d *UserDao) 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 (*UserDao) Structs

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