2
0

Add TxOptions.BeginQuery to allow overriding the default BEGIN query

https://github.com/jackc/pgx/issues/1643
This commit is contained in:
Jack Christensen
2023-06-18 06:43:17 -05:00
parent 737b5af236
commit 9a5ead9048
2 changed files with 28 additions and 0 deletions
+8
View File
@@ -44,6 +44,10 @@ type TxOptions struct {
IsoLevel TxIsoLevel
AccessMode TxAccessMode
DeferrableMode TxDeferrableMode
// BeginQuery is the SQL query that will be executed to begin the transaction. This allows using non-standard syntax
// such as BEGIN PRIORITY HIGH with CockroachDB. If set this will override the other settings.
BeginQuery string
}
var emptyTxOptions TxOptions
@@ -53,6 +57,10 @@ func (txOptions TxOptions) beginSQL() string {
return "begin"
}
if txOptions.BeginQuery != "" {
return txOptions.BeginQuery
}
var buf strings.Builder
buf.Grow(64) // 64 - maximum length of string with available options
buf.WriteString("begin")