2
0

QueryRewriter.RewriteQuery now returns an error

https://github.com/jackc/pgx/issues/1186#issuecomment-1288207250
This commit is contained in:
Jack Christensen
2022-10-29 09:32:35 -05:00
parent 6515e183ff
commit 7d3b9c1e44
4 changed files with 29 additions and 11 deletions
+4 -4
View File
@@ -12,12 +12,12 @@ import (
//
// For example, the following two queries are equivalent:
//
// conn.Query(ctx, "select * from widgets where foo = @foo and bar = @bar", pgx.NamedArgs{"foo": 1, "bar": 2})
// conn.Query(ctx, "select * from widgets where foo = $1 and bar = $2", 1, 2)
// conn.Query(ctx, "select * from widgets where foo = @foo and bar = @bar", pgx.NamedArgs{"foo": 1, "bar": 2})
// conn.Query(ctx, "select * from widgets where foo = $1 and bar = $2", 1, 2)
type NamedArgs map[string]any
// RewriteQuery implements the QueryRewriter interface.
func (na NamedArgs) RewriteQuery(ctx context.Context, conn *Conn, sql string, args []any) (newSQL string, newArgs []any) {
func (na NamedArgs) RewriteQuery(ctx context.Context, conn *Conn, sql string, args []any) (newSQL string, newArgs []any, err error) {
l := &sqlLexer{
src: sql,
stateFn: rawState,
@@ -44,7 +44,7 @@ func (na NamedArgs) RewriteQuery(ctx context.Context, conn *Conn, sql string, ar
newArgs[ordinal-1] = na[string(name)]
}
return sb.String(), newArgs
return sb.String(), newArgs, nil
}
type namedArg string