Files
upstream-mirror 0f4df23290
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
snapshot of https://github.com/sqlc-dev/sqlc.git (main, 2026-09-16; blobs > 131072B omitted)
2026-09-16 02:17:34 +05:00

51 lines
1.2 KiB
Go

package ast
import "github.com/sqlc-dev/sqlc/internal/sql/format"
// In describes a 'select foo in (bar, baz)' type statement, though there are multiple important variants handled.
type In struct {
Tag NodeTag[In] `json:"tag"`
// Expr is the value expression to be compared.
Expr Node `json:"expr,omitempty"`
// List is the list expression in compare list.
List []Node `json:"list,omitempty"`
// Not is true, the expression is "not in".
Not bool `json:"not"`
// Sel is the subquery, may be rewritten to other type of expression.
Sel Node `json:"sel,omitempty"`
Location int `json:"location"`
}
// Pos returns the location.
func (n *In) Pos() int {
return n.Location
}
// Format formats the In expression.
func (n *In) Format(buf *TrackedBuffer, d format.Dialect) {
if n == nil {
return
}
buf.astFormat(n.Expr, d)
if n.Not {
buf.WriteString(" NOT IN ")
} else {
buf.WriteString(" IN ")
}
if n.Sel != nil {
buf.WriteString("(")
buf.astFormat(n.Sel, d)
buf.WriteString(")")
} else if len(n.List) > 0 {
buf.WriteString("(")
for i, item := range n.List {
if i > 0 {
buf.WriteString(", ")
}
buf.astFormat(item, d)
}
buf.WriteString(")")
}
}