(c *Completer, schemas, tables map[string]bool)
| 380 | } |
| 381 | |
| 382 | func (m CompletionMap) insertColumns(c *Completer, schemas, tables map[string]bool) { |
| 383 | if _, exists := c.metadataCache[c.defaultDatabase]; !exists { |
| 384 | _, metadata, err := c.getMetadata(c.ctx, c.instanceID, c.defaultDatabase) |
| 385 | if err != nil || metadata == nil { |
| 386 | return |
| 387 | } |
| 388 | c.metadataCache[c.defaultDatabase] = metadata |
| 389 | } |
| 390 | |
| 391 | for schema := range schemas { |
| 392 | if len(schema) == 0 { |
| 393 | // User didn't specify the schema, we need to append cte tables. |
| 394 | for _, table := range c.cteTables { |
| 395 | if tables[table.Table] { |
| 396 | for _, column := range table.Columns { |
| 397 | m.Insert(base.Candidate{ |
| 398 | Type: base.CandidateTypeColumn, |
| 399 | Text: c.quotedIdentifierIfNeeded(column), |
| 400 | }) |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | continue |
| 405 | } |
| 406 | schemaMeta := c.metadataCache[c.defaultDatabase].GetSchemaMetadata(schema) |
| 407 | if schemaMeta == nil { |
| 408 | continue |
| 409 | } |
| 410 | for table := range tables { |
| 411 | tableMeta := schemaMeta.GetTable(table) |
| 412 | if tableMeta != nil { |
| 413 | for _, column := range tableMeta.GetProto().GetColumns() { |
| 414 | definition := fmt.Sprintf("%s.%s | %s", schema, table, column.Type) |
| 415 | if !column.Nullable { |
| 416 | definition += ", NOT NULL" |
| 417 | } |
| 418 | m.Insert(base.Candidate{ |
| 419 | Type: base.CandidateTypeColumn, |
| 420 | Text: c.quotedIdentifierIfNeeded(column.Name), |
| 421 | Definition: definition, |
| 422 | Comment: column.Comment, |
| 423 | }) |
| 424 | } |
| 425 | continue |
| 426 | } |
| 427 | // Check foreign tables. |
| 428 | if extMeta := schemaMeta.GetExternalTable(table); extMeta != nil { |
| 429 | for _, column := range extMeta.GetProto().GetColumns() { |
| 430 | definition := fmt.Sprintf("%s.%s | %s", schema, table, column.Type) |
| 431 | if !column.Nullable { |
| 432 | definition += ", NOT NULL" |
| 433 | } |
| 434 | m.Insert(base.Candidate{ |
| 435 | Type: base.CandidateTypeColumn, |
| 436 | Text: c.quotedIdentifierIfNeeded(column.Name), |
| 437 | Definition: definition, |
| 438 | Comment: column.Comment, |
| 439 | }) |
no test coverage detected