-
Notifications
You must be signed in to change notification settings - Fork 927
Generic queries with optional params #762
Unanswered
rossb83
asked this question in
Feature Requests & Ideas
-
cc @alecbz
I was thinking it would be neat if there were a way to make a query like this generic with optional params. In the notation below I'm using double question mark ??
to denote an optional param.
/* name: List :many */
SELECT * FROM some_table WHERE col_1 = ?? AND col_2 = ?? AND col_3 = ??
where the generated go struct took in pointers
type ListParams struct {
Col_1 *string
Col_2 *string
Col_3 *string
}
in the above query, 8 queries would actually be generated
/* name: List_0 :many */
SELECT * FROM some_table WHERE col_1 = ? AND col_2 = ? AND col_3 = ?
/* name: List_1 :many */
SELECT * FROM some_table WHERE col_1 = ? AND col_2 = ?
/* name: List_2 :many */
SELECT * FROM some_table WHERE col_1 = ?
/* name: List_3 :many */
SELECT * FROM some_table WHERE col_2 = ? AND col_3 = ?
/* name: List_4 :many */
SELECT * FROM some_table WHERE col_2 = ?
/* name: List_5 :many */
SELECT * FROM some_table WHERE col_1 = ? AND col_3 = ?
/* name: List_6 :many */
SELECT * FROM some_table WHERE col_3 = ?
/* name: List_7 :many */
SELECT * FROM some_table
and the generated go method would re-route to the proper query based on the combination of nil values.
Does this fall in line with the goals of sqlc
and how complex would this be to implement and work with the current functionality?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment