aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/sql.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/database/sql/sql.go')
-rw-r--r--src/database/sql/sql.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go
index 970334269d..616acb2be1 100644
--- a/src/database/sql/sql.go
+++ b/src/database/sql/sql.go
@@ -67,6 +67,27 @@ func Drivers() []string {
return list
}
+// NamedParam may be passed into query parameter arguments to associate
+// a named placeholder with a value.
+type NamedParam struct {
+ // Name of the parameter placeholder. If empty the ordinal position in the
+ // argument list will be used.
+ Name string
+
+ // Value of the parameter. It may be assigned the same value types as
+ // the query arguments.
+ Value interface{}
+}
+
+// Param provides a more concise way to create NamedParam values.
+func Param(name string, value interface{}) NamedParam {
+ // This method exists because the go1compat promise
+ // doesn't guarantee that structs don't grow more fields,
+ // so unkeyed struct literals are a vet error. Thus, we don't
+ // want to encourage sql.NamedParam{name, value}.
+ return NamedParam{Name: name, Value: value}
+}
+
// RawBytes is a byte slice that holds a reference to memory owned by
// the database itself. After a Scan into a RawBytes, the slice is only
// valid until the next call to Next, Scan, or Close.
@@ -1064,7 +1085,7 @@ func (db *DB) exec(ctx context.Context, query string, args []interface{}, strate
}()
if execer, ok := dc.ci.(driver.Execer); ok {
- var dargs []driver.Value
+ var dargs []driver.NamedValue
dargs, err = driverArgs(nil, args)
if err != nil {
return nil, err