Beispiel #1
0
func GetArticles(db *pg.DB, f *ArticleFilter) ([]*Article, error) {
	articles := &Articles{}
	_, err := db.Query(articles, `
        WITH articles (name, category_id) AS (VALUES (?, ?), (?, ?))
        SELECT * FROM articles WHERE 1=1 ?
    `, "article1", 1, "article2", 2, f.CategoryClause())
	if err != nil {
		return nil, err
	}
	return articles.Values, nil
}
Beispiel #2
0
func GetUsers(db *pg.DB) ([]*User, error) {
	users := &Users{}
	_, err := db.Query(users,
		`WITH users (name, emails) AS (VALUES (?, ?), (?, ?))
		SELECT * FROM users`,
		"admin", []string{"admin1@admin", "admin2@admin"},
		"root", []string{"root1@root", "root2@root"},
	)
	if err != nil {
		return nil, err
	}
	return users.Values, nil
}