本文整理匯總了Golang中appworkz/base/api.Err類的典型用法代碼示例。如果您正苦於以下問題:Golang Err類的具體用法?Golang Err怎麽用?Golang Err使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Err類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RemoveForeverByConditions
func (self *Dh) RemoveForeverByConditions(conditions interface{}) api.Err {
var res db.Result
var errs api.Err
res = Collection.Find(conditions)
exist, err := res.Count()
if exist == 0 {
errs.Push(api.Msg{
Field: "Delete: ",
Error: api.ErrNoSuchRow,
})
return errs
}
err = res.Remove()
if err == nil {
return errs
} else {
errs.Push(api.Msg{
Field: "Database delete error: ",
Error: err.Error(),
})
}
return errs
}
示例2: Delete
func (self *Dh) Delete() api.Err {
var res db.Result
var errs api.Err
id := reflect.ValueOf(self.Model).Elem().FieldByName("Id").Interface().(int64)
res = Collection.Find(db.Cond{"id": id})
exist, err := res.Count()
if exist == 0 {
errs.Push(api.Msg{
Field: "Delete: ",
Error: api.ErrNoSuchRow,
})
return errs
}
err = res.Remove()
if err == nil {
return errs
} else {
errs.Push(api.Msg{
Field: "Database delete error: ",
Error: err.Error(),
})
}
return errs
}
示例3: Count
func (self *Dh) Count(query string) int64 {
var errs api.Err
drv := self.SqlDriver()
rows, err := drv.Query(query)
if err != nil {
errs.Push(api.Msg{
Field: "Database select All error: ",
Error: err.Error(),
})
return 0
}
type Total struct {
Count int64 `db:"count"`
}
total := []Total{}
// Mapping to an array.
if err = sqlutil.FetchRows(rows, &total); err != nil {
errs.Push(api.Msg{
Field: "Database select All error: ",
Error: err.Error(),
})
}
defer rows.Close()
return total[0].Count
}
示例4: FindAllByConditionsSortBy
func (self *Dh) FindAllByConditionsSortBy(bar interface{}, conditions interface{}, sort string) api.Err {
var res db.Result
var errs api.Err
res = Collection.Find(conditions).Sort(sort)
err := res.All(bar)
if err != nil {
errs.Push(api.Msg{
Field: "Not found",
Error: api.ErrNoSuchRow,
})
}
return errs
}
示例5: FindAllSortBy
func (self *Dh) FindAllSortBy(bar interface{}, sort string) api.Err {
var res db.Result
var errs api.Err
res = Collection.Find().Sort(sort)
count, _ := res.Count()
if count == 0 {
errs.Push(api.Msg{
Field: "Select All",
Error: api.ErrSelectAll,
})
}
res.All(bar)
return errs
}
示例6: FindByConditions
func (self *Dh) FindByConditions(conditions interface{}) (uint64, api.Err) {
var errs api.Err
var res db.Result
res = Collection.Find(conditions)
count, _ := res.Count()
if count == 0 {
errs.Push(api.Msg{
Field: "Not found",
Error: api.ErrNoSuchRow,
})
return count, errs
}
res.One(self.Model)
return count, errs
}
示例7: FindByFieldValue
func (self *Dh) FindByFieldValue(field string, value interface{}) (interface{}, api.Err) {
var errs api.Err
var res db.Result
res = Collection.Find(db.Cond{field: value})
count, _ := res.Count()
if count == 0 {
errs.Push(api.Msg{
Field: "Not found",
Error: api.ErrNoSuchRow,
})
return nil, errs
}
res.One(self.Model)
return self.Model, errs
}
示例8: FindById
// FindById
// Podemos hacer busquedas por PK Id este metodo
// recibe como parametro la pk de la tabla y trae todos sus
// elementos.
func (self *Dh) FindById(id int64) (interface{}, api.Err) {
var errs api.Err
var res db.Result
res = Collection.Find(db.Cond{"id": id})
count, _ := res.Count()
if count == 0 {
errs.Push(api.Msg{
Field: "Not found",
Error: api.ErrNoSuchRow,
})
return nil, errs
}
res.One(self.Model)
return self.Model, errs
}
示例9: Save
// Nombre: Save()
// Este metodo Guarda una estructura de datos en nuestra base de datos
func (self *Dh) Save() (int64, api.Err) {
var errs api.Err
if exist := self.Exist(); exist {
_, errup := self.Update()
return 0, errup
}
id, err := Collection.Append(self.Model)
if err != nil {
errs.Push(api.Msg{
Field: "DataBase insert error:",
Error: err.Error(),
})
return 0, errs
}
idInsert := id.(int64)
return idInsert, errs
}
示例10: Update
// Nombre: Update
// Este metodo se encarga de actualizar un registro
// si ya fue creado en nuestra base de datos es llamado por el
// metodo save
func (self *Dh) Update() (interface{}, api.Err) {
var errs api.Err
var res db.Result
id := reflect.ValueOf(self.Model).Elem().FieldByName("Id").Interface().(int64)
res = Collection.Find(db.Cond{"id": id})
err := res.Update(self.Model)
if err != nil {
errs.Push(api.Msg{
Field: "Save",
Error: err.Error(),
})
return nil, errs
}
dataUpdate, errr := self.FindById(id)
return dataUpdate, errr
}
示例11: DeleteLogic
func (self *Dh) DeleteLogic() api.Err {
var errs api.Err
var res db.Result
id := reflect.ValueOf(self.Model).Elem().FieldByName("Id").Interface().(int64)
res = Collection.Find(db.Cond{"id": id})
res.One(self.Model)
reflect.ValueOf(self.Model).Elem().FieldByName("Status").SetBool(false)
// Estatus := reflect.ValueOf(self.Model).Elem().FieldByName("Estatus").Interface().(bool)
err := res.Update(self.Model)
if err != nil {
errs.Push(api.Msg{
Field: "Save",
Error: err.Error(),
})
return errs
}
return errs
}