-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathsdk.go
More file actions
59 lines (54 loc) · 1.24 KB
/
sdk.go
File metadata and controls
59 lines (54 loc) · 1.24 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package sdk
import (
"github.com/sqlc-dev/sqlc/internal/pattern"
"github.com/sqlc-dev/sqlc/internal/plugin"
)
func DataType(n *plugin.Identifier) string {
if n.Schema != "" {
return n.Schema + "." + n.Name
} else {
return n.Name
}
}
func MatchString(pat, target string) bool {
matcher, err := pattern.MatchCompile(pat)
if err != nil {
panic(err)
}
return matcher.MatchString(target)
}
func Matches(o *plugin.Override, n *plugin.Identifier, defaultSchema string) bool {
if n == nil {
return false
}
schema := n.Schema
if n.Schema == "" {
schema = defaultSchema
}
if o.Table.Catalog != "" && !MatchString(o.Table.Catalog, n.Catalog) {
return false
}
if o.Table.Schema == "" && schema != "" {
return false
}
if o.Table.Schema != "" && !MatchString(o.Table.Schema, schema) {
return false
}
if o.Table.Name == "" && n.Name != "" {
return false
}
if o.Table.Name != "" && !MatchString(o.Table.Name, n.Name) {
return false
}
return true
}
func SameTableName(tableID, f *plugin.Identifier, defaultSchema string) bool {
if tableID == nil {
return false
}
schema := tableID.Schema
if tableID.Schema == "" {
schema = defaultSchema
}
return tableID.Catalog == f.Catalog && schema == f.Schema && tableID.Name == f.Name
}