示例#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
}
示例#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{"[email protected]", "[email protected]"},
		"root", []string{"[email protected]", "[email protected]"},
	)
	if err != nil {
		return nil, err
	}
	return users.Values, nil
}