(ctx context.Context, ilike, name string, pageSize uint32, pageToken string, conn *sqlx.Conn)
| 465 | } |
| 466 | |
| 467 | func (m *generic) schemaUsingConn(ctx context.Context, ilike, name string, pageSize uint32, pageToken string, conn *sqlx.Conn) ([]*Table, string, error) { |
| 468 | if ilike != "" && name != "" { |
| 469 | return nil, "", fmt.Errorf("cannot specify both `ilike` and `name`") |
| 470 | } |
| 471 | |
| 472 | var whereClause string |
| 473 | var args []any |
| 474 | if ilike != "" { |
| 475 | whereClause = " AND t.table_name ilike ?" |
| 476 | args = []any{ilike} |
| 477 | } else if name != "" { |
| 478 | whereClause = " AND t.table_name = ?" |
| 479 | args = []any{name} |
| 480 | } |
| 481 | |
| 482 | // Add pagination filter |
| 483 | if pageToken != "" { |
| 484 | var startAfterName string |
| 485 | if err := pagination.UnmarshalPageToken(pageToken, &startAfterName); err != nil { |
| 486 | return nil, "", fmt.Errorf("invalid page token: %w", err) |
| 487 | } |
| 488 | whereClause += " AND t.table_name > ?" |
| 489 | args = append(args, startAfterName) |
| 490 | } |
| 491 | |
| 492 | q := fmt.Sprintf(` |
| 493 | SELECT |
| 494 | coalesce(t.table_catalog, current_database()) AS "database", |
| 495 | current_schema() AS "schema", |
| 496 | t.table_name AS "name", |
| 497 | t.table_type = 'VIEW' AS "view", |
| 498 | array_agg(c.column_name ORDER BY c.ordinal_position) AS "column_names", |
| 499 | array_agg(c.data_type ORDER BY c.ordinal_position) AS "column_types", |
| 500 | array_agg(c.is_nullable = 'YES' ORDER BY c.ordinal_position) AS "column_nullable" |
| 501 | FROM information_schema.tables t |
| 502 | JOIN information_schema.columns c |
| 503 | ON t.table_schema = c.table_schema |
| 504 | AND t.table_name = c.table_name |
| 505 | WHERE database = current_database() |
| 506 | AND t.table_schema = current_schema() |
| 507 | %s |
| 508 | GROUP BY ALL |
| 509 | ORDER BY t.table_name |
| 510 | LIMIT ? |
| 511 | `, whereClause) |
| 512 | |
| 513 | limit := pagination.ValidPageSize(pageSize, drivers.DefaultPageSize) |
| 514 | args = append(args, limit+1) |
| 515 | |
| 516 | var res []*Table |
| 517 | err := conn.SelectContext(ctx, &res, q, args...) |
| 518 | if err != nil { |
| 519 | return nil, "", err |
| 520 | } |
| 521 | |
| 522 | next := "" |
| 523 | if len(res) > limit { |
| 524 | res = res[:limit] |
no test coverage detected