MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / getTTLSetting

Function getTTLSetting

plugins/destination/clickhouse/client/client_test.go:446–482  ·  view source on GitHub ↗
(t *testing.T, connection, tableName string)

Source from the content-addressed store, hash-verified

444}
445
446func getTTLSetting(t *testing.T, connection, tableName string) string {
447 t.Helper()
448 options, err := clickhouse.ParseDSN(connection)
449 if err != nil {
450 t.Fatalf("failed to parse connection string: %v", err)
451 }
452 conn, err := clickhouse.Open(options)
453 if err != nil {
454 t.Fatalf("failed to open connection to ClickHouse: %v", err)
455 }
456 rows, err := conn.Query(t.Context(), `SHOW CREATE TABLE `+tableName)
457 if err != nil {
458 t.Fatalf("failed to query ClickHouse for table creation statement: %v", err)
459 }
460 defer func() {
461 require.NoError(t, rows.Close())
462 }()
463 hasRow := rows.Next()
464 if !hasRow {
465 t.Fatalf("no rows returned from SHOW CREATE TABLE query for table %s", tableName)
466 }
467 var statement string
468 if err := rows.Scan(&statement); err != nil {
469 t.Fatal(fmt.Errorf("failed to scan row: %w", err))
470 }
471 ttl := ""
472 for _, line := range strings.Split(statement, "\n") {
473 line = strings.TrimSpace(line)
474 if strings.HasPrefix(line, "TTL") {
475 // Extract the TTL statement, which is everything after "TTL"
476 ttl = strings.TrimPrefix(line, "TTL")
477 ttl = strings.TrimSpace(ttl)
478 break
479 }
480 }
481 return ttl
482}

Callers 1

TestMigrateWithTTLFunction · 0.85

Calls 6

NextMethod · 0.80
ScanMethod · 0.80
ErrorfMethod · 0.80
QueryMethod · 0.65
CloseMethod · 0.65
ContextMethod · 0.45

Tested by

no test coverage detected