to_column.go 638 B

12345678910111213141516171819202122232425262728293031
  1. package compiler
  2. import (
  3. "strings"
  4. "github.com/kyleconroy/sqlc/internal/sql/ast"
  5. "github.com/kyleconroy/sqlc/internal/sql/astutils"
  6. )
  7. func isArray(n *ast.TypeName) bool {
  8. if n == nil {
  9. return false
  10. }
  11. return len(n.ArrayBounds.Items) > 0
  12. }
  13. func toColumn(n *ast.TypeName) *Column {
  14. if n == nil {
  15. panic("can't build column for nil type name")
  16. }
  17. typ, err := ParseTypeName(n)
  18. if err != nil {
  19. panic("toColumn: " + err.Error())
  20. }
  21. return &Column{
  22. Type: typ,
  23. DataType: strings.TrimPrefix(astutils.Join(n.Names, "."), "."),
  24. NotNull: true, // XXX: How do we know if this should be null?
  25. IsArray: isArray(n),
  26. }
  27. }