Example #1
0
// PostInsert ensures that the Attendees list is set in the database
func (i *Invite) PostInsert(s gorp.SqlExecutor) error {
	query := "insert into profile_invite values ($1, $2, $3)"
	for _, a := range i.Attendees {
		_, err := s.Exec(query, a.Id, i.Id, string(a.Status))
		if err != nil {
			return err
		}
	}
	return nil
}
Example #2
0
// PostUpdate clears Flag and Utype information and then sets it correctly.  This
// could definitely be a bit lighter-touch, in the sense that we could diff the
// rows against the struct and only delete and insert some rows, but this might
// actually be faster anyway (and PostgreSQL doesn't have a handy upsert syntax,
// so, whatever).
func (p *Profile) PostUpdate(s gorp.SqlExecutor) error {
	var err error
	// flags
	_, err = s.Exec("delete from profile_flag where profile = $1", p.Id)
	if err != nil {
		return err
	}
	for _, flag := range p.Flags {
		_, err = s.Exec("insert into profile_flag values ($1, $2)", flag.Id, p.Id)
		if err != nil {
			return err
		}
	}
	// types
	if len(p.Utypes) == 0 {
		return errors.New("Profile utype cannot be empty")
	}
	_, err = s.Exec("delete from profile_utype where profile = $1", p.Id)
	if err != nil {
		return err
	}
	for _, t := range p.Utypes {
		_, err = s.Exec("insert into profile_utype values ($1, $2)", t.Id, p.Id)
		if err != nil {
			return err
		}
	}
	return nil
}
Example #3
0
func (m *Member) updateCategoires(s gorp.SqlExecutor) error {
	// delete existing categories
	format := "delete from " + TableNameCategoryMember + " where memberid = ?"
	if _, err := s.Exec(format, m.ID); err != nil {
		return err
	}

	// create new categories
	for _, catId := range m.CategoryIds {
		catMem := NewCategoryMember(catId, m.ID)
		if err := s.Insert(catMem); err != nil {
			return err
		}
	}
	return nil
}
Example #4
0
// PostInsert ensures that the Flags and Utypes are recorded in the database.
func (p *Profile) PostInsert(s gorp.SqlExecutor) error {
	// flags
	for _, flag := range p.Flags {
		_, err := s.Exec("insert into profile_flag values ($1, $2)", flag.Id, p.Id)
		if err != nil {
			return err
		}
	}
	// types
	if len(p.Utypes) == 0 {
		p.Utypes = append(p.Utypes, Utype{1, "Model"})
	}
	for _, t := range p.Utypes {
		_, err := s.Exec("insert into profile_utype values ($1, $2)", t.Id, p.Id)
		if err != nil {
			return err
		}
	}
	return nil
}