Require an ORM in all models
This commit is contained in:
@@ -29,16 +29,14 @@ func init() {
|
||||
|
||||
// AddCompanyUser insert a new CompanyUser into database and returns
|
||||
// last inserted Id on success.
|
||||
func AddCompanyUser(m *CompanyUser) (id int64, err error) {
|
||||
o := orm.NewOrm()
|
||||
func AddCompanyUser(o orm.Ormer, m *CompanyUser) (id int64, err error) {
|
||||
id, err = o.Insert(m)
|
||||
return
|
||||
}
|
||||
|
||||
// GetCompanyUserById retrieves CompanyUser by Id. Returns error if
|
||||
// Id doesn't exist
|
||||
func GetCompanyUserById(id int) (v *CompanyUser, err error) {
|
||||
o := orm.NewOrm()
|
||||
func GetCompanyUserById(o orm.Ormer, id int) (v *CompanyUser, err error) {
|
||||
v = &CompanyUser{Id: id}
|
||||
if err = o.Read(v); err == nil {
|
||||
return v, nil
|
||||
@@ -48,9 +46,8 @@ func GetCompanyUserById(id int) (v *CompanyUser, err error) {
|
||||
|
||||
// GetAllCompanyUser retrieves all CompanyUser matches certain condition. Returns empty list if
|
||||
// no records exist
|
||||
func GetAllCompanyUser(query map[string]string, fields []string, sortby []string, order []string,
|
||||
func GetAllCompanyUser(o orm.Ormer, query map[string]string, fields []string, sortby []string, order []string,
|
||||
offset int64, limit int64) (ml []interface{}, err error) {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(new(CompanyUser))
|
||||
// query k=v
|
||||
for k, v := range query {
|
||||
@@ -124,10 +121,8 @@ func GetAllCompanyUser(query map[string]string, fields []string, sortby []string
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// UpdateCompanyUser updates CompanyUser by Id and returns error if
|
||||
// the record to be updated doesn't exist
|
||||
func UpdateCompanyUserById(m *CompanyUser) (err error) {
|
||||
o := orm.NewOrm()
|
||||
// UpdateCompanyUserById updates CompanyUser by Id and returns error if the record to be updated doesn't exist
|
||||
func UpdateCompanyUserById(o orm.Ormer, m *CompanyUser) (err error) {
|
||||
v := CompanyUser{Id: m.Id}
|
||||
// ascertain id exists in the database
|
||||
if err = o.Read(&v); err == nil {
|
||||
@@ -141,8 +136,7 @@ func UpdateCompanyUserById(m *CompanyUser) (err error) {
|
||||
|
||||
// DeleteCompanyUser deletes CompanyUser by Id and returns error if
|
||||
// the record to be deleted doesn't exist
|
||||
func DeleteCompanyUser(id int) (err error) {
|
||||
o := orm.NewOrm()
|
||||
func DeleteCompanyUser(o orm.Ormer, id int) (err error) {
|
||||
v := CompanyUser{Id: id}
|
||||
// ascertain id exists in the database
|
||||
if err = o.Read(&v); err == nil {
|
||||
|
Reference in New Issue
Block a user