• 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-sqlite/driver/parser/types.go
1
package parser
2

3
import (
4
        "slices"
5
        "strings"
6

7
        antlrhelpers "github.com/stephenafamo/bob/gen/bobgen-helpers/parser/antlrhelpers"
8
        "github.com/stephenafamo/bob/gen/drivers"
9
        sqliteparser "github.com/stephenafamo/sqlparser/sqlite"
10
)
11

12
type (
13
        tables     = drivers.Tables[any, IndexExtra]
14
        IndexExtra = struct {
15
                Partial bool `json:"partial"`
16
        }
17

18
        Node         = antlrhelpers.Node
19
        NodeKey      = antlrhelpers.NodeKey
20
        NodeType     = antlrhelpers.NodeType
21
        NodeTypes    = antlrhelpers.NodeTypes
22
        NodeInfo     = antlrhelpers.NodeInfo
23
        ReturnColumn = antlrhelpers.ReturnColumn
24
        QuerySource  = antlrhelpers.QuerySource
25
        StmtInfo     = antlrhelpers.StmtInfo
26
        Function     = antlrhelpers.Function
27
        Functions    = antlrhelpers.Functions
28
)
29

30
type identifiable interface {
31
        Identifier() sqliteparser.IIdentifierContext
32
}
33

UNCOV
34
func getName(i identifiable) string {
×
UNCOV
35
        if i == nil {
×
UNCOV
36
                return ""
×
UNCOV
37
        }
×
UNCOV
38
        ctx := i.Identifier()
×
UNCOV
39
        for ctx.OPEN_PAR() != nil {
×
40
                ctx = ctx.Identifier()
×
41
        }
×
42

UNCOV
43
        txt := ctx.GetText()
×
UNCOV
44
        if strings.ContainsAny(string(txt[0]), "\"`[") {
×
45
                return txt[1 : len(txt)-1]
×
46
        }
×
47

UNCOV
48
        return txt
×
49
}
50

NEW
51
func makeRef(sources []QuerySource, ctx *sqliteparser.Expr_qualified_column_nameContext) NodeTypes {
×
UNCOV
52
        schema := getName(ctx.Schema_name())
×
UNCOV
53
        table := getName(ctx.Table_name())
×
UNCOV
54
        column := getName(ctx.Column_name())
×
UNCOV
55
        if schema == "main" {
×
56
                schema = ""
×
57
        }
×
58

UNCOV
59
        for _, source := range slices.Backward(sources) {
×
NEW
60
                if table != "" && (schema != source.Schema || table != source.Name) {
×
61
                        continue
×
62
                }
63

NEW
64
                for _, col := range source.Columns {
×
NEW
65
                        if col.Name != column {
×
UNCOV
66
                                continue
×
67
                        }
68

NEW
69
                        return col.Type
×
70
                }
71
        }
72

UNCOV
73
        return nil
×
74
}
75

NEW
76
func getColumnType(db tables, schema, table, column string) NodeType {
×
NEW
77
        if schema == "main" {
×
NEW
78
                schema = ""
×
UNCOV
79
        }
×
80

NEW
81
        colType := antlrhelpers.GetColumnType(db, schema, table, column)
×
NEW
82
        colType.DBType = getTypeFromTypeName(colType.DBType)
×
UNCOV
83

×
NEW
84
        return colType
×
85
}
86

NEW
87
func knownType(t string, nullable func() bool) NodeType {
×
NEW
88
        return NodeType{
×
NEW
89
                DBType:    getTypeFromTypeName(t),
×
NEW
90
                NullableF: nullable,
×
UNCOV
91
        }
×
UNCOV
92
}
×
93

94
// https://www.sqlite.org/datatype3.html
95
//
96
//nolint:misspell
NEW
97
func getTypeFromTypeName(t string) string {
×
UNCOV
98
        if t == "" {
×
UNCOV
99
                return ""
×
UNCOV
100
        }
×
101

UNCOV
102
        if strings.Contains(t, "INT") {
×
UNCOV
103
                return "INTEGER"
×
UNCOV
104
        }
×
105

UNCOV
106
        if strings.Contains(t, "CHAR") || strings.Contains(t, "CLOB") || strings.Contains(t, "TEXT") {
×
UNCOV
107
                return "TEXT"
×
UNCOV
108
        }
×
109

UNCOV
110
        if strings.Contains(t, "BLOB") {
×
111
                return "BLOB"
×
112
        }
×
113

UNCOV
114
        if strings.Contains(t, "REAL") || strings.Contains(t, "FLOA") || strings.Contains(t, "DOUB") {
×
UNCOV
115
                return "REAL"
×
UNCOV
116
        }
×
117

UNCOV
118
        return "NUMERIC"
×
119
}
120

UNCOV
121
func nullable() bool {
×
UNCOV
122
        return true
×
UNCOV
123
}
×
124

UNCOV
125
func notNullable() bool {
×
UNCOV
126
        return false
×
UNCOV
127
}
×
128

UNCOV
129
func anyNullable(fs ...func() bool) func() bool {
×
UNCOV
130
        return func() bool {
×
UNCOV
131
                for _, f := range fs {
×
UNCOV
132
                        if f() {
×
133
                                return true
×
134
                        }
×
135
                }
136

UNCOV
137
                return false
×
138
        }
139
}
140

141
func allNullable(fs ...func() bool) func() bool {
×
142
        return func() bool {
×
143
                for _, f := range fs {
×
144
                        if !f() {
×
145
                                return false
×
146
                        }
×
147
                }
148

149
                return true
×
150
        }
151
}
152

153
func neverNullable(...func() bool) func() bool {
×
154
        return notNullable
×
155
}
×
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