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)
| 168 | // loadDatabaseObjects fully loads one database's tables and views into the |
| 169 | // catalog, under that database's namespace. |
| 170 | func 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. |
no test coverage detected