MCPcopy Index your code
hub / github.com/rilldata/rill / schemaUsingConn

Method schemaUsingConn

runtime/pkg/rduckdb/generic.go:467–529  ·  view source on GitHub ↗
(ctx context.Context, ilike, name string, pageSize uint32, pageToken string, conn *sqlx.Conn)

Source from the content-addressed store, hash-verified

465}
466
467func (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]

Callers 2

dropTableUnsafeMethod · 0.95
SchemaMethod · 0.95

Calls 5

UnmarshalPageTokenFunction · 0.92
ValidPageSizeFunction · 0.92
MarshalPageTokenFunction · 0.92
SelectContextMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected