(ctx context.Context, query interface{})
| 216 | } |
| 217 | |
| 218 | func (p *PostgreSQL) QueryLog(ctx context.Context, query interface{}) ([]interface{}, int64, error) { |
| 219 | postgresqlQueryParam := new(QueryParam) |
| 220 | if err := mapstructure.Decode(query, postgresqlQueryParam); err != nil { |
| 221 | return nil, 0, err |
| 222 | } |
| 223 | if postgresqlQueryParam.Database != "" { |
| 224 | p.Shards[0].DB = postgresqlQueryParam.Database |
| 225 | } else { |
| 226 | db, err := parseDBName(postgresqlQueryParam.SQL) |
| 227 | if err != nil { |
| 228 | return nil, 0, err |
| 229 | } |
| 230 | p.Shards[0].DB = db |
| 231 | } |
| 232 | |
| 233 | postgresqlQueryParam.SQL = formatSQLDatabaseNameWithRegex(postgresqlQueryParam.SQL) |
| 234 | if strings.Contains(postgresqlQueryParam.SQL, "$__") { |
| 235 | var err error |
| 236 | postgresqlQueryParam.SQL, err = macros.Macro(postgresqlQueryParam.SQL, postgresqlQueryParam.From, postgresqlQueryParam.To) |
| 237 | if err != nil { |
| 238 | return nil, 0, err |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | timeout := p.Shards[0].Timeout |
| 243 | if timeout == 0 { |
| 244 | timeout = 60 |
| 245 | } |
| 246 | timeoutCtx, cancel := context.WithTimeout(ctx, time.Duration(timeout)*time.Second) |
| 247 | defer cancel() |
| 248 | items, err := p.Shards[0].Query(timeoutCtx, &sqlbase.QueryParam{ |
| 249 | Sql: postgresqlQueryParam.SQL, |
| 250 | }) |
| 251 | if err != nil { |
| 252 | logger.Warningf("query:%+v get data err:%v", postgresqlQueryParam, err) |
| 253 | return []interface{}{}, 0, err |
| 254 | } |
| 255 | logs := make([]interface{}, 0) |
| 256 | for i := range items { |
| 257 | logs = append(logs, items[i]) |
| 258 | } |
| 259 | |
| 260 | return logs, 0, nil |
| 261 | } |
| 262 | |
| 263 | func (p *PostgreSQL) DescribeTable(ctx context.Context, query interface{}) ([]*types.ColumnProperty, error) { |
| 264 | postgresqlQueryParam := new(QueryParam) |
nothing calls this directly
no test coverage detected