MCPcopy Index your code
hub / github.com/bytebase/bytebase / loadDatabaseObjects

Function loadDatabaseObjects

backend/plugin/parser/tidb/completion.go:170–195  ·  view source on GitHub ↗

loadDatabaseObjects fully loads one database's tables and views into the catalog, under that database's namespace.

(ctx context.Context, cCtx base.CompletionContext, cat *catalog.Catalog, dbName string)

Source from the content-addressed store, hash-verified

168// loadDatabaseObjects fully loads one database's tables and views into the
169// catalog, under that database's namespace.
170func loadDatabaseObjects(ctx context.Context, cCtx base.CompletionContext, cat *catalog.Catalog, dbName string) {
171 db := backtickIdentifier(dbName)
172 _, dbMeta, err := cCtx.Metadata(ctx, cCtx.InstanceID, dbName)
173 if err != nil || dbMeta == nil {
174 // Still register the name so it can be a database candidate.
175 _, _ = cat.Exec("CREATE DATABASE "+db+";", &catalog.ExecOptions{ContinueOnError: true})
176 return
177 }
178 if _, err := cat.Exec("CREATE DATABASE "+db+"; USE "+db+";", &catalog.ExecOptions{ContinueOnError: true}); err != nil {
179 return
180 }
181 schema := dbMeta.GetSchemaMetadata("")
182 if schema == nil {
183 return
184 }
185 for _, tableName := range schema.ListTableNames() {
186 if table := schema.GetTable(tableName); table != nil {
187 defineTable(cat, tableName, table.GetProto().GetColumns())
188 }
189 }
190 for _, viewName := range schema.ListViewNames() {
191 if view := schema.GetView(viewName); view != nil {
192 defineView(cat, viewName, view.GetDefinition())
193 }
194 }
195}
196
197// listAllDatabaseNames returns the instance's database names, or nil if the
198// completion context cannot enumerate them.

Callers 1

buildCatalogFunction · 0.85

Calls 11

backtickIdentifierFunction · 0.85
defineTableFunction · 0.85
defineViewFunction · 0.85
GetSchemaMetadataMethod · 0.80
ListTableNamesMethod · 0.80
ListViewNamesMethod · 0.80
GetTableMethod · 0.45
GetColumnsMethod · 0.45
GetProtoMethod · 0.45
GetViewMethod · 0.45
GetDefinitionMethod · 0.45

Tested by

no test coverage detected