本文整理汇总了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
}