ParseConfigWithOptions behaves exactly as [ParseConfig] does with the addition of options. At the present options is only used to provide a [pgconn.GetSSLPasswordFunc] function.
(connString string, options ParseConfigOptions)
| 163 | // ParseConfigWithOptions behaves exactly as [ParseConfig] does with the addition of options. At the present options is |
| 164 | // only used to provide a [pgconn.GetSSLPasswordFunc] function. |
| 165 | func ParseConfigWithOptions(connString string, options ParseConfigOptions) (*ConnConfig, error) { |
| 166 | config, err := pgconn.ParseConfigWithOptions(connString, options.ParseConfigOptions) |
| 167 | if err != nil { |
| 168 | return nil, err |
| 169 | } |
| 170 | |
| 171 | statementCacheCapacity := 512 |
| 172 | if s, ok := config.RuntimeParams["statement_cache_capacity"]; ok { |
| 173 | delete(config.RuntimeParams, "statement_cache_capacity") |
| 174 | n, err := strconv.ParseInt(s, 10, 32) |
| 175 | if err != nil { |
| 176 | return nil, pgconn.NewParseConfigError(connString, "cannot parse statement_cache_capacity", err) |
| 177 | } |
| 178 | statementCacheCapacity = int(n) |
| 179 | } |
| 180 | |
| 181 | descriptionCacheCapacity := 512 |
| 182 | if s, ok := config.RuntimeParams["description_cache_capacity"]; ok { |
| 183 | delete(config.RuntimeParams, "description_cache_capacity") |
| 184 | n, err := strconv.ParseInt(s, 10, 32) |
| 185 | if err != nil { |
| 186 | return nil, pgconn.NewParseConfigError(connString, "cannot parse description_cache_capacity", err) |
| 187 | } |
| 188 | descriptionCacheCapacity = int(n) |
| 189 | } |
| 190 | |
| 191 | defaultQueryExecMode := QueryExecModeCacheStatement |
| 192 | if s, ok := config.RuntimeParams["default_query_exec_mode"]; ok { |
| 193 | delete(config.RuntimeParams, "default_query_exec_mode") |
| 194 | switch s { |
| 195 | case "cache_statement": |
| 196 | defaultQueryExecMode = QueryExecModeCacheStatement |
| 197 | case "cache_describe": |
| 198 | defaultQueryExecMode = QueryExecModeCacheDescribe |
| 199 | case "describe_exec": |
| 200 | defaultQueryExecMode = QueryExecModeDescribeExec |
| 201 | case "exec": |
| 202 | defaultQueryExecMode = QueryExecModeExec |
| 203 | case "simple_protocol": |
| 204 | defaultQueryExecMode = QueryExecModeSimpleProtocol |
| 205 | default: |
| 206 | return nil, pgconn.NewParseConfigError( |
| 207 | connString, "invalid default_query_exec_mode", fmt.Errorf("unknown value %q", s), |
| 208 | ) |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | connConfig := &ConnConfig{ |
| 213 | Config: *config, |
| 214 | createdByParseConfig: true, |
| 215 | StatementCacheCapacity: statementCacheCapacity, |
| 216 | DescriptionCacheCapacity: descriptionCacheCapacity, |
| 217 | DefaultQueryExecMode: defaultQueryExecMode, |
| 218 | connString: connString, |
| 219 | } |
| 220 | |
| 221 | return connConfig, nil |
| 222 | } |
no test coverage detected