forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
37 lines (33 loc) · 838 Bytes
/
utils.go
File metadata and controls
37 lines (33 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package sqlite
import (
"github.com/kyleconroy/sqlc/internal/engine/sqlite/parser"
"github.com/kyleconroy/sqlc/internal/sql/ast"
)
type tableNamer interface {
Table_name() parser.ITable_nameContext
Database_name() parser.IDatabase_nameContext
}
func parseTableName(c tableNamer) *ast.TableName {
name := ast.TableName{
Name: c.Table_name().GetText(),
}
if c.Database_name() != nil {
name.Schema = c.Database_name().GetText()
}
return &name
}
func hasNotNullConstraint(checks []parser.IColumn_constraintContext) bool {
for i := range checks {
constraint, ok := checks[i].(*parser.Column_constraintContext)
if !ok {
continue
}
if constraint.K_PRIMARY() != nil && constraint.K_KEY() != nil {
return true
}
if constraint.K_NOT() != nil && constraint.K_NULL() != nil {
return true
}
}
return false
}