Esempio n. 1
0
func (t *PostTag) Delete(db sqruct.DB) error {
	b, tbl := zzPostTag{}.DeleteBuilder()
	sql, args := b.Where(
		q.Eq(tbl.PostID(), t.PostID),
		q.Eq(tbl.TagID(), t.TagID),
	).ToSQL()
	_, err := db.Exec(sql, args...)
	return err
}
Esempio n. 2
0
func GetPostTag(db sqruct.DB, postID int64, tagID int64) (*PostTag, error) {
	b, tbl := zzPostTag{}.SelectBuilder()
	sql, args := b.Where(
		q.Eq(tbl.PostID(), postID),
		q.Eq(tbl.TagID(), tagID),
	).ToSQL()
	var t PostTag
	err := db.QueryRow(sql, args...).Scan(zzPostTag{}.Pointers(&t)...)
	if err != nil {
		return nil, err
	}
	return &t, nil
}
Esempio n. 3
0
File: zzpost.go Progetto: 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
}
Esempio n. 4
0
func (t *Account) Delete(db sqruct.DB) error {
	b, tbl := zzAccount{}.DeleteBuilder()
	sql, args := b.Where(
		q.Eq(tbl.ID(), t.ID),
	).ToSQL()
	_, err := db.Exec(sql, args...)
	return err
}
Esempio n. 5
0
File: zzpost.go Progetto: oov/sqruct
func (t *Post) Update(db sqruct.DB) error {
	b, tbl := zzPost{}.UpdateBuilder(t)
	sql, args := b.Where(
		q.Eq(tbl.ID(), t.ID),
	).ToSQL()
	_, err := db.Exec(sql, args...)
	return err
}
Esempio n. 6
0
File: zzpost.go Progetto: oov/sqruct
func (zzPost) SelectBuilderForTag() (b *q.ZSelectBuilder, postTag *zzPostTagTable, tag *zzTagTable) {
	b, relTbl := zzPostTag{}.SelectBuilder()
	oTbl := zzTag{}.T()
	relTbl.InnerJoin(
		oTbl,
		q.Eq(relTbl.TagID(), oTbl.ID()),
	)
	zzTag{}.Columns(b, oTbl)
	return b, relTbl, oTbl
}
Esempio n. 7
0
File: zzpost.go Progetto: oov/sqruct
func (t *Post) GetAccount(db sqruct.DB) (*Account, error) {
	b, tbl := zzAccount{}.SelectBuilder()
	sql, args := b.Where(
		q.Eq(tbl.ID(), t.AccountID),
	).ToSQL()
	var ot Account
	if err := db.QueryRow(sql, args...).Scan(zzAccount{}.Pointers(&ot)...); err != nil {
		return nil, err
	}
	return &ot, nil
}
Esempio n. 8
0
func (t *PostTag) GetTag(db sqruct.DB) (*Tag, error) {
	b, tbl := zzTag{}.SelectBuilder()
	sql, args := b.Where(
		q.Eq(tbl.ID(), t.TagID),
	).ToSQL()
	var ot Tag
	if err := db.QueryRow(sql, args...).Scan(zzTag{}.Pointers(&ot)...); err != nil {
		return nil, err
	}
	return &ot, nil
}
Esempio n. 9
0
func GetAccount(db sqruct.DB, id int64) (*Account, error) {
	b, tbl := zzAccount{}.SelectBuilder()
	sql, args := b.Where(
		q.Eq(tbl.ID(), id),
	).ToSQL()
	var t Account
	err := db.QueryRow(sql, args...).Scan(zzAccount{}.Pointers(&t)...)
	if err != nil {
		return nil, err
	}
	return &t, nil
}
Esempio n. 10
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
}