Skip to content

Commit 64c2e4d

Browse files
committed
Move pattern matching to another package
1 parent f2922a2 commit 64c2e4d

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

internal/codegen/python/gen.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"strings"
1010

1111
"github.com/kyleconroy/sqlc/internal/codegen"
12-
"github.com/kyleconroy/sqlc/internal/config"
1312
"github.com/kyleconroy/sqlc/internal/inflection"
1413
"github.com/kyleconroy/sqlc/internal/metadata"
14+
"github.com/kyleconroy/sqlc/internal/pattern"
1515
"github.com/kyleconroy/sqlc/internal/plugin"
1616
pyast "github.com/kyleconroy/sqlc/internal/python/ast"
1717
"github.com/kyleconroy/sqlc/internal/python/poet"
@@ -210,9 +210,8 @@ func pyInnerType(req *plugin.CodeGenRequest, col *plugin.Column) string {
210210
}
211211
}
212212

213-
func matchString(pattern, target string) bool {
214-
// TODO: Create a separate package for the matchers
215-
matcher, err := config.MatchCompile(pattern)
213+
func matchString(pat, target string) bool {
214+
matcher, err := pattern.MatchCompile(pat)
216215
if err != nil {
217216
panic(err)
218217
}

internal/config/config.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"strings"
1111

12+
"github.com/kyleconroy/sqlc/internal/pattern"
1213
"github.com/kyleconroy/sqlc/internal/sql/ast"
1314

1415
yaml "gopkg.in/yaml.v3"
@@ -169,10 +170,10 @@ type Override struct {
169170
// fully qualified name of the column, e.g. `accounts.id`
170171
Column string `json:"column" yaml:"column"`
171172

172-
ColumnName *Match
173-
TableCatalog *Match
174-
TableSchema *Match
175-
TableRel *Match
173+
ColumnName *pattern.Match
174+
TableCatalog *pattern.Match
175+
TableSchema *pattern.Match
176+
TableRel *pattern.Match
176177
GoImportPath string
177178
GoPackage string
178179
GoTypeName string
@@ -242,36 +243,36 @@ func (o *Override) Parse() (err error) {
242243
colParts := strings.Split(o.Column, ".")
243244
switch len(colParts) {
244245
case 2:
245-
if o.ColumnName, err = MatchCompile(colParts[1]); err != nil {
246+
if o.ColumnName, err = pattern.MatchCompile(colParts[1]); err != nil {
246247
return err
247248
}
248-
if o.TableRel, err = MatchCompile(colParts[0]); err != nil {
249+
if o.TableRel, err = pattern.MatchCompile(colParts[0]); err != nil {
249250
return err
250251
}
251-
if o.TableSchema, err = MatchCompile("public"); err != nil {
252+
if o.TableSchema, err = pattern.MatchCompile("public"); err != nil {
252253
return err
253254
}
254255
case 3:
255-
if o.ColumnName, err = MatchCompile(colParts[2]); err != nil {
256+
if o.ColumnName, err = pattern.MatchCompile(colParts[2]); err != nil {
256257
return err
257258
}
258-
if o.TableRel, err = MatchCompile(colParts[1]); err != nil {
259+
if o.TableRel, err = pattern.MatchCompile(colParts[1]); err != nil {
259260
return err
260261
}
261-
if o.TableSchema, err = MatchCompile(colParts[0]); err != nil {
262+
if o.TableSchema, err = pattern.MatchCompile(colParts[0]); err != nil {
262263
return err
263264
}
264265
case 4:
265-
if o.ColumnName, err = MatchCompile(colParts[3]); err != nil {
266+
if o.ColumnName, err = pattern.MatchCompile(colParts[3]); err != nil {
266267
return err
267268
}
268-
if o.TableRel, err = MatchCompile(colParts[2]); err != nil {
269+
if o.TableRel, err = pattern.MatchCompile(colParts[2]); err != nil {
269270
return err
270271
}
271-
if o.TableSchema, err = MatchCompile(colParts[1]); err != nil {
272+
if o.TableSchema, err = pattern.MatchCompile(colParts[1]); err != nil {
272273
return err
273274
}
274-
if o.TableCatalog, err = MatchCompile(colParts[0]); err != nil {
275+
if o.TableCatalog, err = pattern.MatchCompile(colParts[0]); err != nil {
275276
return err
276277
}
277278
default:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package config
1+
package pattern
22

33
import (
44
"fmt"

0 commit comments

Comments
 (0)