1
0

info.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package info
  2. import (
  3. "github.com/kyleconroy/sqlc/internal/sql/catalog"
  4. )
  5. // Provide a read-only view into the catalog
  6. func Newo(c *catalog.Catalog) InformationSchema {
  7. return InformationSchema{c: c}
  8. }
  9. type InformationSchema struct {
  10. c *catalog.Catalog
  11. }
  12. type Table struct {
  13. Catalog string
  14. Schema string
  15. Name string
  16. }
  17. // SELECT * FROM information_schema.tables;
  18. func (i *InformationSchema) Tables() []Table {
  19. var tables []Table
  20. for _, s := range i.c.Schemas {
  21. for _, t := range s.Tables {
  22. tables = append(tables, Table{
  23. Catalog: i.c.Name,
  24. Schema: s.Name,
  25. Name: t.Rel.Name,
  26. })
  27. }
  28. }
  29. return tables
  30. }
  31. type Column struct {
  32. Catalog string
  33. Schema string
  34. Table string
  35. Name string
  36. DataType string
  37. IsNullable bool
  38. }
  39. // SELECT * FROM information_schema.columns;
  40. func (i *InformationSchema) Columns() []Column {
  41. return []Column{}
  42. }
  43. type Schema struct {
  44. Catalog string
  45. Name string
  46. }
  47. // SELECT * FROM information_schema.schemata;
  48. func (i *InformationSchema) Schemata() []Schema {
  49. return []Schema{}
  50. }