Instance Method
finish()
Render the builder’s combined unions into an
SQLExpression which may be used as a subquery.func finish() -> some SQLExpression
Discussion
The same effect can be achieved by writing .union instead of .finish(), but providing an explicit “complete the union” API improves readability and makes the intent more explicit, whereas using yet another meaning of the term “union” for the third time in rapid succession is nothing but confusing. It was confusing enough coming up with the subquery API for unions at all.
Example:
try await db.update("foos")
.set(SQLIdentifier("bar_id"), to: SQLSubquery
.union { $0
.column("id")
.from("bars")
.where("baz", .notEqual, "bamf")
}
.union(all: { $0
.column("id")
.from("bars")
.where("baz", .equal, "bop")
})
.finish()
)
.run()