Postgres components: Adds `queryExecMode` option (#3103)
Signed-off-by: Bernd Verst <github@bernd.dev>
This commit is contained in:
parent
247b08a70c
commit
81539d0b53
|
@ -79,3 +79,16 @@ metadata:
|
|||
sensitive: true
|
||||
example: |
|
||||
"user=dapr password=secret host=dapr.example.com port=5432 dbname=dapr sslmode=verify-ca"
|
||||
- name: queryExecMode
|
||||
required: false
|
||||
description: |
|
||||
Controls the default mode for executing queries. By default Dapr uses the extended protocol and automatically prepares and caches prepared statements.
|
||||
However, this may be incompatible with proxies such as PGBouncer. In this case it may be preferrable to use `exec` or `simple_protocol`.
|
||||
allowedValues:
|
||||
- "cache_statement"
|
||||
- "cache_describe"
|
||||
- "describe_exec"
|
||||
- "exec"
|
||||
- "simple_protocol"
|
||||
example: "cache_describe"
|
||||
default: ""
|
|
@ -67,4 +67,17 @@ metadata:
|
|||
description: |
|
||||
Deprecated alias for 'connectionMaxIdleTime'.
|
||||
example: "5m"
|
||||
type: duration
|
||||
type: duration
|
||||
- name: queryExecMode
|
||||
required: false
|
||||
description: |
|
||||
Controls the default mode for executing queries. By default Dapr uses the extended protocol and automatically prepares and caches prepared statements.
|
||||
However, this may be incompatible with proxies such as PGBouncer. In this case it may be preferrable to use `exec` or `simple_protocol`.
|
||||
allowedValues:
|
||||
- "cache_statement"
|
||||
- "cache_describe"
|
||||
- "describe_exec"
|
||||
- "exec"
|
||||
- "simple_protocol"
|
||||
example: "cache_describe"
|
||||
default: ""
|
|
@ -32,6 +32,7 @@ type PostgresAuthMetadata struct {
|
|||
ConnectionMaxIdleTime time.Duration `mapstructure:"connectionMaxIdleTime"`
|
||||
MaxConns int `mapstructure:"maxConns"`
|
||||
UseAzureAD bool `mapstructure:"useAzureAD"`
|
||||
QueryExecMode string `mapstructure:"queryExecMode"`
|
||||
|
||||
azureEnv azure.EnvironmentSettings
|
||||
}
|
||||
|
@ -42,6 +43,7 @@ func (m *PostgresAuthMetadata) Reset() {
|
|||
m.ConnectionMaxIdleTime = 0
|
||||
m.MaxConns = 0
|
||||
m.UseAzureAD = false
|
||||
m.QueryExecMode = ""
|
||||
}
|
||||
|
||||
// InitWithMetadata inits the object with metadata from the user.
|
||||
|
@ -81,6 +83,21 @@ func (m *PostgresAuthMetadata) GetPgxPoolConfig() (*pgxpool.Config, error) {
|
|||
config.MaxConns = int32(m.MaxConns)
|
||||
}
|
||||
|
||||
if m.QueryExecMode != "" {
|
||||
queryExecModes := map[string]pgx.QueryExecMode{
|
||||
"cache_statement": pgx.QueryExecModeCacheStatement,
|
||||
"cache_describe": pgx.QueryExecModeCacheDescribe,
|
||||
"describe_exec": pgx.QueryExecModeDescribeExec,
|
||||
"exec": pgx.QueryExecModeExec,
|
||||
"simple_protocol": pgx.QueryExecModeSimpleProtocol,
|
||||
}
|
||||
if mode, ok := queryExecModes[m.QueryExecMode]; ok {
|
||||
config.ConnConfig.DefaultQueryExecMode = mode
|
||||
} else {
|
||||
return nil, fmt.Errorf("invalid queryExecMode metadata value: %s", m.QueryExecMode)
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we should use Azure AD
|
||||
if m.UseAzureAD {
|
||||
tokenCred, errToken := m.azureEnv.GetTokenCredential()
|
||||
|
|
|
@ -93,3 +93,16 @@ metadata:
|
|||
database driver to choose.
|
||||
example: "5m"
|
||||
type: duration
|
||||
- name: queryExecMode
|
||||
required: false
|
||||
description: |
|
||||
Controls the default mode for executing queries. By default Dapr uses the extended protocol and automatically prepares and caches prepared statements.
|
||||
However, this may be incompatible with proxies such as PGBouncer. In this case it may be preferrable to use `exec` or `simple_protocol`.
|
||||
allowedValues:
|
||||
- "cache_statement"
|
||||
- "cache_describe"
|
||||
- "describe_exec"
|
||||
- "exec"
|
||||
- "simple_protocol"
|
||||
example: "cache_describe"
|
||||
default: ""
|
Loading…
Reference in New Issue