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

Method schemaTables

plugins/destination/mysql/client/schema.go:82–113  ·  view source on GitHub ↗

TODO: in the future this could theoretically be done in a single query and then the tables could be filtered in memory

(ctx context.Context, tables schema.Tables)

Source from the content-addressed store, hash-verified

80
81// TODO: in the future this could theoretically be done in a single query and then the tables could be filtered in memory
82func (c *Client) schemaTables(ctx context.Context, tables schema.Tables) (schema.Tables, error) {
83 query := `SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND (DATABASE() IS NULL OR table_SCHEMA = DATABASE());`
84 rows, err := c.db.QueryContext(ctx, query)
85 if err != nil {
86 return nil, err
87 }
88 defer rows.Close()
89 schemaTables := make(schema.Tables, 0)
90 tableNames := make([]string, 0)
91 for rows.Next() {
92 var tableName string
93
94 if err := rows.Scan(&tableName); err != nil {
95 return nil, err
96 }
97
98 if tables.Get(tableName) == nil {
99 continue
100 }
101 tableNames = append(tableNames, tableName)
102 }
103
104 for _, tableName := range tableNames {
105 fields, err := c.getTableColumns(ctx, tableName)
106 if err != nil {
107 return nil, err
108 }
109 schemaTables = append(schemaTables, &schema.Table{Name: tableName, Columns: fields})
110 }
111
112 return schemaTables, nil
113}
114
115func (c *Client) addColumn(ctx context.Context, table *schema.Table, column *schema.Column) error {
116 builder := strings.Builder{}

Callers 1

MigrateTablesMethod · 0.95

Calls 5

getTableColumnsMethod · 0.95
NextMethod · 0.80
ScanMethod · 0.80
CloseMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected