Last active
November 18, 2016 03:26
-
-
Save fuzzmonkey/f2e6e64cf01a5c7cb26fbc636370996e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sql := "SELECT * FROM foo WHERE foo.name = $1" | |
args = append(args, "fred") | |
someArg := r.URL.Query().Get("some_arg") | |
someArg2 := r.URL.Query().Get("some_arg_2") | |
if someArg != "" { | |
args = append(args, someArg) | |
sql += " AND foo.some_arg = $" + strconv.Itoa(len(args)) | |
} | |
if someArg2 != "" { | |
args = append(args, someArg2) | |
sql += " AND foo.some_arg_2 = $" + strconv.Itoa(len(args)) | |
} | |
rows, qerr := db.Query(sql, args...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment