goqu icon indicating copy to clipboard operation
goqu copied to clipboard

how to add Identifier to struct select

Open RaymondReddington opened this issue 3 years ago • 1 comments

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")

RaymondReddington avatar Mar 26 '21 03:03 RaymondReddington

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 AS a1.c, a1.d AS a1.d, a1.e AS a1.e, b1.cc AS b1.cc, b1.dd AS b1.dd, b1.ff AS b1.ff

RaymondReddington avatar Mar 27 '21 04:03 RaymondReddington