Skip to content

Commit 91af153

Browse files
Dragon-Huang0403kyleconroy
authored andcommitted
feat: allow spaces between the embed keyword and the struct name
1 parent 46ffd02 commit 91af153

File tree

3 files changed

+81
-7
lines changed

3 files changed

+81
-7
lines changed

examples/batch/postgresql/batch.go

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/batch/postgresql/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/sql/rewrite/embeds.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@ package rewrite
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/sqlc-dev/sqlc/internal/sql/ast"
78
"github.com/sqlc-dev/sqlc/internal/sql/astutils"
89
)
910

1011
// Embed is an instance of `sqlc.embed(param)`
1112
type Embed struct {
12-
Table *ast.TableName
13-
param string
14-
Node *ast.ColumnRef
13+
Table *ast.TableName
14+
param string
15+
origin string
16+
Node *ast.ColumnRef
1517
}
1618

1719
// Orig string to replace
1820
func (e Embed) Orig() string {
19-
return fmt.Sprintf("sqlc.embed(%s)", e.param)
21+
return e.origin
2022
}
2123

2224
// EmbedSet is a set of Embed instances
@@ -60,10 +62,16 @@ func Embeds(raw *ast.RawStmt) (*ast.RawStmt, EmbedSet) {
6062
},
6163
}
6264

65+
// Get the origin string
66+
const noSpaceLen = 11
67+
spaceCount := fun.Args.Items[0].Pos() - fun.Pos() - noSpaceLen
68+
origin := fmt.Sprintf("sqlc.embed%s(%s)", strings.Repeat(" ", spaceCount), param)
69+
6370
embeds = append(embeds, &Embed{
64-
Table: &ast.TableName{Name: param},
65-
param: param,
66-
Node: node,
71+
Table: &ast.TableName{Name: param},
72+
param: param,
73+
origin: origin,
74+
Node: node,
6775
})
6876

6977
cr.Replace(node)

0 commit comments

Comments
 (0)