v0.18.0
Breaking Changes in v0.18.0
Comparison methods now require an expression (bob.Expression
)
The primary breaking change is that several builder methods now require a bob.Expression
instead of any
.
While this makes building some simple queries more verbose, it makes it harder to make some errors.
As an example, consider the following query
// SELECT * FROM users WHERE id = 1
psql.Select(
sm.From("users"),
sm.Where(psql.X("id").EQ(1)),
)
This feels like the natural way to build this query, however there are some subtle potential issues:
-
1
should probably be passed as an argument. In a real world application, this could lead to an SQL injection.// SELECT * FROM users WHERE id = $1 psql.Select( sm.From("users"), sm.Where(psql.X("id").EQ(psql.Arg(1))), )
-
This query will throw an error if we use a string
// !!!!INVALID QUERY!!!! // SELECT * FROM users WHERE name = Stephen psql.Select( sm.From("users"), sm.Where(psql.X("name").EQ("Stephen")), )
The initial reason why these took any
was to make Bob easy to adopt. However, after using this in practice, it is likely that the user always wants to do something to make it an expression.
- If it is a table or column name, it should probably be quoted with
psql.Quote
- If it is an argument, it should be passed with
psql.Arg
No more X
builder
The X
builder, while convenient doesn't quite fit in anywhere. Most queries will be started with a quote, and can then be fluently chained with other expressions.
In the interest of keeping the surface area of this pacakge small, I've decided to remove it until there is a concrete need.
No more P
builder method
The P
builder method was for adding parentheses to a single expression. However, this overlaps with the Group
method with adds parentheses around a list of expressions separated with a comma.
Since using the Group
method with a single expression does the same thing as the P
method, the P
method now feels redundant.