func (this *UserService) CanRegistered(userName string, email string) (canName bool, canEmail bool, err error) { cond := orm.NewCondition() cond = cond.Or("Username", userName).Or("email", email) var maps []orm.Params var n int64 n, err = this.Queryable().SetCond(cond).Values(&maps, "Username", "email") if err != nil { return false, false, err } canName = true canEmail = true if n > 0 { for _, m := range maps { if canName && orm.ToStr(m["Username"]) == userName { canName = false } if canEmail && orm.ToStr(m["Email"]) == email { canEmail = false } } } return canName, canEmail, nil }
func CanRegistered(userName string, email string) (bool, bool, error) { cond := orm.NewCondition() cond = cond.Or("UserName", userName).Or("Email", email) var maps []orm.Params o := orm.NewOrm() n, err := o.QueryTable("user").SetCond(cond).Values(&maps, "UserName", "Email") if err != nil { return false, false, err } e1 := true e2 := true if n > 0 { for _, m := range maps { if e1 && orm.ToStr(m["UserName"]) == userName { e1 = false } if e2 && orm.ToStr(m["Email"]) == email { e2 = false } } } return e1, e2, nil }
func (c *CSVDataFile) AppendRow(record ...interface{}) error { var err error c.writer = csv.NewWriter(c.fh) c.writer.Comma = c.FieldsTerminatedBy recordToWrite := make([]string, len(record)) for k, v := range record { recordToWrite[k] = c.quoteField(orm.ToStr(v)) } err = c.writer.Write(recordToWrite) return err }
func ToStr(v interface{}) string { return orm.ToStr(v) }