Example #1
0
func (c Country) Update() error {
	session, database := common.Session()
	defer common.Close(session)

	country := database.C(collection)
	return country.Update(bson.M{"_id": c.Id}, c)
}
Example #2
0
func (c Country) Create() error {
	session, database := common.Session()
	defer common.Close(session)

	country := database.C(collection)
	return country.Insert(&c)
}
Example #3
0
func All() ([]Country, error) {
	session, database := common.Session()
	defer common.Close(session)

	country := database.C(collection)
	result := []Country{}
	if err := country.Find(bson.M{}).All(&result); err != nil {
		return nil, err
	}

	return result, nil
}
Example #4
0
func FindById(id string) (Country, error) {
	session, database := common.Session()
	defer common.Close(session)

	country := database.C(collection)
	result := Country{}

	if bson.IsObjectIdHex(id) {
		err := country.FindId(bson.ObjectIdHex(id)).One(&result)
		return result, err
	} else {
		return result, errors.New(fmt.Sprintf("Invalid Object Id: %s", id))
	}
}