Example #1
0
File: zzpost.go Project: oov/sqruct
func (t *Post) SelectTag(db sqruct.DB) ([]Tag, []PostTag, error) {
	b, relTbl, _ := zzPost{}.SelectBuilderForTag()
	sql, args := b.Where(
		q.Eq(relTbl.PostID(), t.ID),
	).ToSQL()
	r, err := db.Query(sql, args...)
	if err != nil {
		return nil, nil, err
	}
	defer r.Close()

	ot, rt := []Tag{}, []PostTag{}
	for r.Next() {
		var oe Tag
		var re PostTag
		if err = r.Scan(append(zzPostTag{}.Pointers(&re), zzTag{}.Pointers(&oe)...)...); err != nil {
			return nil, nil, err
		}
		ot, rt = append(ot, oe), append(rt, re)
	}
	if err = r.Err(); err != nil {
		return nil, nil, err
	}
	return ot, rt, nil
}
Example #2
0
func (t *Account) SelectPost(db sqruct.DB) ([]Post, error) {
	b, tbl := zzPost{}.SelectBuilder()
	sql, args := b.Where(
		q.Eq(tbl.AccountID(), t.ID),
	).ToSQL()
	r, err := db.Query(sql, args...)
	if err != nil {
		return nil, err
	}
	defer r.Close()

	ot := []Post{}
	for r.Next() {
		var e Post
		if err = r.Scan(zzPost{}.Pointers(&e)...); err != nil {
			return nil, err
		}
		ot = append(ot, e)
	}
	if err = r.Err(); err != nil {
		return nil, err
	}
	return ot, nil
}