本文整理匯總了Golang中github.com/opesun/nocrud/frame/interfaces.Filter.Insert方法的典型用法代碼示例。如果您正苦於以下問題:Golang Filter.Insert方法的具體用法?Golang Filter.Insert怎麽用?Golang Filter.Insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/opesun/nocrud/frame/interfaces.Filter
的用法示例。
在下文中一共展示了Filter.Insert方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Insert
func (e *Entries) Insert(a iface.Filter, data map[string]interface{}) error {
e.getOptions(a.Subject())
from := data["from"].(int64)
length := data["length"].(int64)
prof, err := e.db.ToId(data["professional"].(string))
if err != nil {
return err
}
err = e.intervalIsValid(data, prof, length)
if err != nil {
return err
}
to := from + length*60
err = e.okAccordingToTimeTable(data, from, to)
if err != nil {
return err
}
err = e.othersAlreadyTook(a, from, to)
if err != nil {
return err
}
i := map[string]interface{}{
"createdBy": e.userId,
"from": from,
"to": to,
"length": length,
"day": dateToString(from),
"forProfessional": prof,
}
return a.Insert(i)
}
示例2: Save
func (tt *TimeTable) Save(a iface.Filter, data map[string]interface{}) error {
if !tt.userIsProfessional {
return fmt.Errorf("Only professionals can save timetables.")
}
ssl := toSS(data["timeTable"].([]interface{}))
timeTable, err := evenday.StringsToTimeTable(ssl)
if err != nil {
return err
}
count, err := a.Count()
if err != nil {
return err
}
m := map[string]interface{}{}
m["createdBy"] = tt.userId
m["timeTable"] = timeTable
if count == 0 {
return a.Insert(m)
} else if count == 1 {
doc, err := a.SelectOne()
if err != nil {
return err
}
return doc.Update(m)
}
_, err = a.RemoveAll()
if err != nil {
return err
}
return a.Insert(m)
}
示例3: Insert
func (c *C) Insert(a iface.Filter, data map[string]interface{}) error {
m, err := c.decrypt(data)
if err != nil {
return err
}
m["created"] = time.Now().UnixNano() // Should include user too maybe.
return a.Insert(m)
}
示例4: RegisterUser
func RegisterUser(a iface.Filter, db iface.Db, user map[string]interface{}) (iface.Id, error) {
user["password"] = hashPass(user["password"].(string))
if _, has := user["level"]; !has {
user["level"] = 100
}
user_id := db.NewId()
user["_id"] = user_id
err := a.Insert(user)
if err != nil {
return nil, fmt.Errorf("Name is not unique.")
}
return user_id, nil
}
示例5: Insert
func (b *Basics) Insert(a iface.Filter, data map[string]interface{}) (iface.Id, error) {
id := b.Db.NewId()
data["_id"] = id
err := a.Insert(data)
if err != nil {
return nil, err
}
if b.Hooks != nil {
q := map[string]interface{}{
"_id": id,
}
filt := a.Clone().AddQuery(q)
b.Hooks.Select("Inserted").Fire(filt)
b.Hooks.Select(a.Subject() + "Inserted").Fire(filt)
}
return id, nil
}