goqu
goqu copied to clipboard
how to add Identifier to struct select
type A struct { C string D string } type B struct { C string D string } type AB struct { A B } goqu.From("a").Select(&AB{}).Join("b")
how to generate sql like: select a.C a.D, b.C, b.D from a join b ?
i need this when join two table, and there are some column name equal in the two table
maybe something like this?
goqu.From("a").Select(goqu.T("a").Cols(&AB{})).Join("b")
i got this
type A1 struct {
C string
D string
E string
}
type B1 struct {
C string `db:"cc"`
D string `db:"dd"`
F string `db:"ff"`
}
type AB struct {
A1 `db:"a1"`
B1 `db:"b1"`
}
s, _, err = goqu.Select(&AB{}).
WithDialect("mysql").
ToSQL()
fmt.Printf("err:%#v,sql9:%s\n", err, s)
SELECT
a1
.c
ASa1.c
,a1
.d
ASa1.d
,a1
.e
ASa1.e
,b1
.cc
ASb1.cc
,b1
.dd
ASb1.dd
,b1
.ff
ASb1.ff