MCPcopy Create free account
hub / github.com/bytebase/bytebase / showCreateDDL

Method showCreateDDL

backend/plugin/db/hive/dump.go:165–199  ·  view source on GitHub ↗
(ctx context.Context, objectType string, objectName string)

Source from the content-addressed store, hash-verified

163}
164
165func (d *Driver) showCreateDDL(ctx context.Context, objectType string, objectName string) (string, error) {
166 objectName = fmt.Sprintf("`%s`", objectName)
167
168 // 'SHOW CREATE TABLE' can also be used for dumping views
169 stmt := fmt.Sprintf("SHOW CREATE %s %s", objectType, objectName)
170 if objectType == "VIEW" {
171 stmt = fmt.Sprintf("SHOW CREATE TABLE %s", objectName)
172 }
173
174 rows, err := d.db.QueryContext(ctx, stmt)
175 if err != nil {
176 return "", errors.Wrapf(err, "failed to execute %s", stmt)
177 }
178 defer rows.Close()
179
180 var schemaDDL strings.Builder
181 for rows.Next() {
182 var ddlLine string
183 if err := rows.Scan(&ddlLine); err != nil {
184 return "", errors.Wrap(err, "failed to scan DDL row")
185 }
186 schemaDDL.WriteString(ddlLine)
187 schemaDDL.WriteString("\n")
188 }
189
190 if err := rows.Err(); err != nil {
191 return "", errors.Wrap(err, "error reading DDL rows")
192 }
193
194 if schemaDDL.Len() == 0 {
195 return "", errors.New("empty DDL result")
196 }
197
198 return fmt.Sprintf(schemaStmtFmt, objectType, objectName, schemaDDL.String()), nil
199}
200
201func genIndexDDL(opts *IndexDDLOptions) (string, error) {
202 var builder strings.Builder

Callers 1

DumpMethod · 0.95

Implementers 15

MockDriverbackend/plugin/advisor/utils_for_tests
Driverbackend/plugin/db/bigquery/bigquery.go
Driverbackend/plugin/db/mongodb/mongodb.go
Driverbackend/plugin/db/trino/trino.go
Driverbackend/plugin/db/redshift/redshift.go
Driverbackend/plugin/db/oracle/oracle.go
Driverbackend/plugin/db/dynamodb/dynamodb.go
Driverbackend/plugin/db/cosmosdb/cosmosdb.go
Driverbackend/plugin/db/spanner/spanner.go
Driverbackend/plugin/db/mssql/mssql.go
Driverbackend/plugin/db/mysql/mysql.go
Driverbackend/plugin/db/pg/pg.go

Calls 6

QueryContextMethod · 0.80
ScanMethod · 0.80
LenMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.65
NextMethod · 0.45

Tested by

no test coverage detected