Skip to content

Commit

Permalink
Rename to ComplexExpression.
Browse files Browse the repository at this point in the history
SubQuery means something specific in SQL and we don't want to confuse
people by reusing an existing term and giving it a new meaning. Instead,
let's call it a complex expression, which is more evocative of what it's
used for.
  • Loading branch information
paddycarver committed Aug 2, 2023
1 parent fe38a1e commit 381c780
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ func (q *Query) PostgreSQLString() (string, error) {
return res + ";", nil
}

// SubQuery starts a Query with a new buffer, so it can be flushed without
// affecting the outer Query's buffer of expressions.
// ComplexExpression starts a Query with a new buffer, so it can be flushed
// without affecting the outer Query's buffer of expressions.
//
// Once a SubQuery has been flushed, it should have its AppendToParent method
// called, which sets the entire SubQuery as a single expression on its parent
// Query.
func (q *Query) SubQuery(query string) *Query {
// Once a ComplexExpression has been flushed, it should have its AppendToParent
// method called, which sets the entire ComplexExpression as a single
// expression on its parent Query.
func (q *Query) ComplexExpression(query string) *Query {
return &Query{
sql: query,
args: []any{},
Expand All @@ -190,13 +190,14 @@ func (q *Query) SubQuery(query string) *Query {
}

// AppendToParent sets the entire Query as a single expression on its parent
// Query. It should only be called on Querys created by calling SubQuery;
// calling it on a Query that isn't a SubQuery will panic.
// Query. It should only be called on Querys created by calling
// ComplexExpression; calling it on a Query that isn't a ComplexExpression will
// panic.
//
// It returns the parent of the Query.
func (q *Query) AppendToParent() *Query {
if q.parent == nil {
panic("can't call AppendToParent on a Query that wasn't created using Query.SubQuery")
panic("can't call AppendToParent on a Query that wasn't created using Query.ComplexExpression")
}
if len(q.expressions) > 0 {
panic(ErrNeedsFlush)
Expand Down

0 comments on commit 381c780

Please sign in to comment.