extends.go 380 B

1234567891011121314151617181920
  1. package ldap
  2. import (
  3. "errors"
  4. "github.com/astaxie/beego/orm"
  5. )
  6. func InsertOrUpdate(o orm.Ormer, md interface{}, colConflitAndArgs ...string) (int64, error) {
  7. if o == nil {
  8. o = orm.NewOrm()
  9. }
  10. err := o.Read(md, colConflitAndArgs...)
  11. if err != nil && errors.Is(err, orm.ErrNoRows) {
  12. return o.Insert(md)
  13. } else if err != nil {
  14. return 0, err
  15. }
  16. return o.Update(md)
  17. }