Esempio n. 1
0
File: tbl.go Progetto: RyanDeng/qbot
func (t *ReminderTbl) Insert(reminder *Reminder) error {
	c := qmgo.CopyCollection(t.coll)
	defer qmgo.CloseCollection(c)

	reminder.CreatedAt = time.Now().UnixNano()

	return c.Insert(reminder)
}
Esempio n. 2
0
File: tbl.go Progetto: RyanDeng/qbot
func (t *ContactTbl) Insert(contact *Contact) error {
	c := qmgo.CopyCollection(t.coll)
	defer qmgo.CloseCollection(c)

	contact.CreatedAt = time.Now().UnixNano()

	return c.Insert(contact)
}
Esempio n. 3
0
File: tbl.go Progetto: RyanDeng/qbot
func (t *ReminderTbl) GetAndDelete() (r Reminder, ok bool, err error) {

	c := qmgo.CopyCollection(t.coll)
	defer qmgo.CloseCollection(c)

	now := time.Now().UnixNano()

	q := M{"time": M{"$lte": now}}
	err = c.Find(q).One(&r)
	if err == nil {
		c.Remove(M{"to": "312798705"})
		ok = true
	}
	if err == mgo.ErrNotFound {
		err = nil
	}
	return
}
Esempio n. 4
0
File: tbl.go Progetto: RyanDeng/qbot
func (t *ContactTbl) SearchByAllName(name string) (contacts []Contact, err error) {
	c := qmgo.CopyCollection(t.coll)
	defer qmgo.CloseCollection(c)

	sel := M{
		"$or": []M{
			M{"name": name},
			M{"nickname": name},
		},
	}
	fmt.Println("search condition", sel)

	err = c.Find(sel).All(&contacts)
	fmt.Println(contacts)
	if err == mgo.ErrNotFound {
		err = nil
	}
	return
}