• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stephenafamo / bob / 14939098091

09 May 2025 10:59PM UTC coverage: 36.868% (-4.6%) from 41.506%
14939098091

push

github

stephenafamo
Move reusable sqlite parser components to antlrhelpers package

0 of 758 new or added lines in 12 files covered. (0.0%)

547 existing lines in 8 files now uncovered.

6533 of 17720 relevant lines covered (36.87%)

212.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/gen/bobgen-helpers/parser/antlrhelpers/node_type.go
1
package antlrhelpers
2

3
import (
4
        "fmt"
5

6
        "github.com/stephenafamo/bob/gen/drivers"
7
)
8

9
type NodeTypes []NodeType
10

NEW
11
func (e NodeTypes) ConfirmedDBType() string {
×
NEW
12
        if len(e) == 0 {
×
NEW
13
                return ""
×
NEW
14
        }
×
15

NEW
16
        fristType := e[0].DBType
×
NEW
17

×
NEW
18
        for _, t := range e[1:] {
×
NEW
19
                if t.DBType != fristType {
×
NEW
20
                        return ""
×
NEW
21
                }
×
22
        }
23

NEW
24
        return fristType
×
25
}
26

NEW
27
func (e NodeTypes) Nullable() bool {
×
NEW
28
        for _, t := range e {
×
NEW
29
                if t.Nullable() {
×
NEW
30
                        return true
×
NEW
31
                }
×
32
        }
33

NEW
34
        return false
×
35
}
36

37
// Get the common types between the two sets of node types.
NEW
38
func (existing NodeTypes) Match(newTypes NodeTypes) NodeTypes {
×
NEW
39
        matchingDBTypes := NodeTypes{}
×
NEW
40
Outer:
×
NEW
41
        for _, t := range newTypes {
×
NEW
42
                for _, ct := range existing {
×
NEW
43
                        merged, ok := mergeTypes(t, ct)
×
NEW
44
                        if ok {
×
NEW
45
                                matchingDBTypes = append(matchingDBTypes, merged)
×
NEW
46
                                continue Outer
×
47
                        }
48
                }
49
        }
50

NEW
51
        return matchingDBTypes
×
52
}
53

NEW
54
func (e NodeTypes) List() []string {
×
NEW
55
        m := make([]string, len(e))
×
NEW
56
        for i, expr := range e {
×
NEW
57
                m[i] = expr.String()
×
NEW
58
        }
×
59

NEW
60
        return m
×
61
}
62

63
type NodeType struct {
64
        DBType    string
65
        NullableF func() bool
66
}
67

NEW
68
func (e NodeType) Nullable() bool {
×
NEW
69
        if e.NullableF != nil {
×
NEW
70
                return e.NullableF()
×
NEW
71
        }
×
72

NEW
73
        return false
×
74
}
75

NEW
76
func mergeTypes(e, e2 NodeType) (NodeType, bool) {
×
NEW
77
        switch {
×
NEW
78
        case e.NullableF != nil && e2.NullableF != nil:
×
NEW
79
                current := e.NullableF()
×
NEW
80
                e.NullableF = func() bool {
×
NEW
81
                        return current || e2.NullableF()
×
NEW
82
                }
×
83

NEW
84
        case e2.NullableF != nil:
×
NEW
85
                e.NullableF = e2.NullableF
×
86
        }
87

NEW
88
        if e2.DBType == "" {
×
NEW
89
                return e, true
×
NEW
90
        }
×
91

NEW
92
        if e.DBType == "" {
×
NEW
93
                e.DBType = e2.DBType
×
NEW
94
                return e, true
×
NEW
95
        }
×
96

NEW
97
        return e, e.DBType == e2.DBType
×
98
}
99

NEW
100
func (e NodeType) String() string {
×
NEW
101
        if e.Nullable() {
×
NEW
102
                return fmt.Sprintf("%s NULLABLE", e.DBType)
×
NEW
103
        }
×
104

NEW
105
        return fmt.Sprintf("%s NOT NULL", e.DBType)
×
106
}
107

NEW
108
func GetColumnType[C, I any](db drivers.Tables[C, I], schema, table, column string) NodeType {
×
NEW
109
        if schema == "" && table == "" {
×
NEW
110
                // Find first table with matching column
×
NEW
111
                for _, table := range db {
×
NEW
112
                        for _, col := range table.Columns {
×
NEW
113
                                if col.Name == column {
×
NEW
114
                                        return NodeType{
×
NEW
115
                                                DBType:    col.DBType,
×
NEW
116
                                                NullableF: func() bool { return col.Nullable },
×
117
                                        }
118
                                }
119
                        }
120
                }
NEW
121
                panic(fmt.Sprintf("could not find column name: %q in %#v", column, db))
×
122
        }
123

NEW
124
        key := fmt.Sprintf("%s.%s", schema, table)
×
NEW
125
        if schema == "" {
×
NEW
126
                key = table
×
NEW
127
        }
×
128

NEW
129
        col := db.GetColumn(key, column)
×
NEW
130

×
NEW
131
        return NodeType{
×
NEW
132
                DBType:    col.DBType,
×
NEW
133
                NullableF: func() bool { return col.Nullable },
×
134
        }
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc