entc/integration: add examples for sub-queries + minor fixed for selector builder (#2509)

* dialect/sql: move FROM to inside switch

* dialect/sql: adds simple example of subquery usage

* dialect/sql: adds a more complex example with join

* Apply suggestions from code review

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>

* dialect/sql: fix missing type and change modify to where

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
This commit is contained in:
Pedro Henrique
2022-05-05 16:46:13 -03:00
committed by GitHub
parent 0c75ffc007
commit 4d1c0af20d
3 changed files with 36 additions and 1 deletions

View File

@@ -2657,12 +2657,13 @@ func (s *Selector) Query() (string, []interface{}) {
} else {
b.WriteString("*")
}
b.WriteString(" FROM ")
switch t := s.from.(type) {
case *SelectTable:
b.WriteString(" FROM ")
t.SetDialect(s.dialect)
b.WriteString(t.ref())
case *Selector:
b.WriteString(" FROM ")
t.SetDialect(s.dialect)
b.Nested(func(b *Builder) {
b.Join(t)
@@ -2670,6 +2671,7 @@ func (s *Selector) Query() (string, []interface{}) {
b.WriteString(" AS ")
b.Ident(t.as)
case *WithBuilder:
b.WriteString(" FROM ")
t.SetDialect(s.dialect)
b.Ident(t.Name())
}