Skip to content

Commit 836de61

Browse files
committed
Don't include _ in variable names
1 parent 0400406 commit 836de61

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

parser.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,15 @@ func parseArgs(t postgres.Table, args []paramRef) []Arg {
392392
}
393393
}
394394
if typ, ok := typeMap[key]; ok {
395-
a = append(a, Arg{Name: key, Type: typ})
395+
a = append(a, Arg{Name: argName(key), Type: typ})
396396
} else {
397397
panic("unknown column: " + key)
398398
}
399399
}
400400
case nodes.ResTarget:
401401
key := *n.Name
402402
if typ, ok := typeMap[key]; ok {
403-
a = append(a, Arg{Name: key, Type: typ})
403+
a = append(a, Arg{Name: argName(key), Type: typ})
404404
} else {
405405
panic("unknown column: " + key)
406406
}
@@ -601,6 +601,20 @@ type Arg struct {
601601
Type string
602602
}
603603

604+
func argName(name string) string {
605+
out := ""
606+
for i, p := range strings.Split(name, "_") {
607+
if i == 0 {
608+
out += strings.ToLower(p)
609+
} else if p == "id" {
610+
out += "ID"
611+
} else {
612+
out += strings.Title(p)
613+
}
614+
}
615+
return out
616+
}
617+
604618
type tmplCtx struct {
605619
Q string
606620
Package string

postgres/schema.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package postgres
22

3+
import "log"
4+
35
type Schema struct {
46
Tables []Table
57
}
@@ -28,6 +30,16 @@ func (c Column) GoType() string {
2830
}
2931
case "serial":
3032
return "int"
33+
case "integer":
34+
return "int"
35+
case "bool":
36+
return "bool"
37+
case "pg_catalog.bool":
38+
return "bool"
39+
case "pg_catalog.int4":
40+
return "int"
41+
case "pg_catalog.int8":
42+
return "int"
3143
case "pg_catalog.timestamp":
3244
return "time.Time"
3345
case "pg_catalog.varchar":
@@ -37,6 +49,7 @@ func (c Column) GoType() string {
3749
return "sql.NullString"
3850
}
3951
default:
52+
log.Printf("unknown Postgres type: %s\n", c.Type)
4053
return "interface{}"
4154
}
4255
}

testdata/ondeck/db.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ INSERT INTO venue (
137137
) RETURNING id
138138
`
139139

140-
func (q *Queries) CreateVenue(ctx context.Context, name string, slug string, spotify_playlist string, city string) (int, error) {
140+
func (q *Queries) CreateVenue(ctx context.Context, name string, slug string, spotifyPlaylist string, city string) (int, error) {
141141
var row *sql.Row
142142
switch {
143143
case q.createVenue != nil && q.tx != nil:
144-
row = q.tx.StmtContext(ctx, q.createVenue).QueryRowContext(ctx, name, slug, spotify_playlist, city)
144+
row = q.tx.StmtContext(ctx, q.createVenue).QueryRowContext(ctx, name, slug, spotifyPlaylist, city)
145145
case q.createVenue != nil:
146-
row = q.createVenue.QueryRowContext(ctx, name, slug, spotify_playlist, city)
146+
row = q.createVenue.QueryRowContext(ctx, name, slug, spotifyPlaylist, city)
147147
default:
148-
row = q.db.QueryRowContext(ctx, createVenue, name, slug, spotify_playlist, city)
148+
row = q.db.QueryRowContext(ctx, createVenue, name, slug, spotifyPlaylist, city)
149149
}
150150
var i int
151151
err := row.Scan(&i)

0 commit comments

Comments
 (0)