Skip to content

Commit 42ae5cd

Browse files
refactor: separated template files between stdlib and pgx
1 parent 039ba4c commit 42ae5cd

8 files changed

Lines changed: 447 additions & 441 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/kyleconroy/sqlc
22

3-
go 1.15
3+
go 1.16
44

55
require (
66
github.com/antlr/antlr4 v0.0.0-20200209180723-1177c0b58d07

internal/codegen/golang/gen.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package golang
33
import (
44
"bufio"
55
"bytes"
6+
"embed"
67
"fmt"
78
"go/format"
89
"strings"
@@ -13,6 +14,11 @@ import (
1314
"github.com/kyleconroy/sqlc/internal/config"
1415
)
1516

17+
//go:embed templates/*
18+
//go:embed templates/pgx/*
19+
//go:embed templates/stdlib/*
20+
var content embed.FS
21+
1622
type Generateable interface {
1723
Structs(settings config.CombinedSettings) []Struct
1824
GoQueries(settings config.CombinedSettings) []Query
@@ -64,7 +70,16 @@ func generate(settings config.CombinedSettings, enums []Enum, structs []Struct,
6470
"imports": i.Imports,
6571
}
6672

67-
tmpl := template.Must(template.New("table").Funcs(funcMap).Parse(templateSet))
73+
tmpl := template.Must(
74+
template.New("table").
75+
Funcs(funcMap).
76+
ParseFS(
77+
content,
78+
"templates/*.txt",
79+
"templates/pgx/*.txt",
80+
"templates/stdlib/*.txt",
81+
),
82+
)
6883

6984
golang := settings.Go
7085
tctx := tmplCtx{

0 commit comments

Comments
 (0)