Beispiel #1
0
// Returns the first db.Item that matches the given conditions.
func (self *SourceCollection) Find(terms ...interface{}) (db.Item, error) {
	terms = append(terms, db.Limit(1))

	result, err := self.FindAll(terms...)

	if len(result) > 0 {
		return result[0], nil
	}

	return nil, err
}
Beispiel #2
0
/*
	Returns the first row in the table that matches certain conditions.
*/
func (self *Table) Find(terms ...interface{}) (db.Item, error) {
	var item db.Item
	var err error

	terms = append(terms, db.Limit(1))

	res, err := self.Query(terms...)

	if err == nil {
		err = res.One(&item)
	}

	return item, err
}
Beispiel #3
0
// Tests limit and offset.
func TestLimitOffset(t *testing.T) {
	var err error

	sess, err := db.Open(wrapperName, settings)

	if err != nil {
		t.Fatalf(err.Error())
	}

	defer sess.Close()

	people, _ := sess.Collection("people")

	items, _ := people.FindAll(db.Limit(2), db.Offset(1))

	if len(items) != 2 {
		t.Fatalf("Test failed")
	}

}