-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Arg() for generating the argument placeholder for use in the query
- Loading branch information
Ferdy Pruis
committed
Feb 25, 2022
1 parent
5279df4
commit a9071f7
Showing
6 changed files
with
52 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package sqeasy | ||
|
||
import ( | ||
"strconv" | ||
) | ||
|
||
// Arg adds a value to args, returning it's position | ||
func Arg(args *[]interface{}, arg interface{}) string { | ||
*args = append(*args, arg) | ||
return `$` + strconv.Itoa(len(*args)) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package sqeasy | ||
|
||
import ( | ||
"database/sql" | ||
"time" | ||
) | ||
|
||
func ExampleArg() { | ||
var db *sql.DB | ||
|
||
var args []interface{} | ||
query := `SELECT * FROM table WHERE a_column = ` + Arg(&args, `fubar`) + ` AND timestamp < ` + Arg(&args, time.Now()) | ||
|
||
_ = db.QueryRow(query, args...) | ||
} |
This file contains 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
This file contains 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
This file contains 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