utils.go 822 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package sqlite
  2. import (
  3. "github.com/sqlc-dev/sqlc/internal/engine/sqlite/parser"
  4. "github.com/sqlc-dev/sqlc/internal/sql/ast"
  5. )
  6. type tableNamer interface {
  7. Table_name() parser.ITable_nameContext
  8. Schema_name() parser.ISchema_nameContext
  9. }
  10. func parseTableName(c tableNamer) *ast.TableName {
  11. name := ast.TableName{
  12. Name: c.Table_name().GetText(),
  13. }
  14. if c.Schema_name() != nil {
  15. name.Schema = c.Schema_name().GetText()
  16. }
  17. return &name
  18. }
  19. func hasNotNullConstraint(checks []parser.IColumn_constraintContext) bool {
  20. for i := range checks {
  21. constraint, ok := checks[i].(*parser.Column_constraintContext)
  22. if !ok {
  23. continue
  24. }
  25. if constraint.PRIMARY_() != nil && constraint.KEY_() != nil {
  26. return true
  27. }
  28. if constraint.NOT_() != nil && constraint.NULL_() != nil {
  29. return true
  30. }
  31. }
  32. return false
  33. }