19.0.0 (2019-09-19)
Bug Fixes
Features
- remove multiple methods in favor of sql.join (910177d)
BREAKING CHANGES
-
The latest changes remove a large number of helper methods for building queries:
-
assignmentList
-
booleanExpression
-
comparisonPredicate
-
identifierList
-
rawList
-
tuple
-
tupleList
-
valueList
The original motivation for having these methods was to provide static types that are specific to different contexts of the query (e.g. identifier list containing only of identifier tokens). However, as programs using Slonik grew in complexity, so did the requirements for having more complex expressions: a requirement to support any SQL expressions in all of the contexts became evident. This made strict types less useful.
Meanwhile, the API has proliferated with a long list of methods that carry semantic significance but do not significantly differ in their functionality. This created an unnecessary steep learning curve for new adopters and confusing code when any of those methods is misused (e.g. describing value list using tuple list would create confusion about the intent of the code).
All of the removed methods shared a common requirement: to create an expression consisting of a dynamic number of members. This requirement was implemented using a new method sql.join
. sql.join
works similar to Array.join
and it can be used to express any of the above methods, e.g.
sql.tuple(['foo', 'bar'])
can be writen as:
sql`
(${sql.list([
sql.identifier('foo'),
sql.identifier('bar')
]sql`, `)})
`
both produce:
(foo, bar)
assignmentList
and comparisonPredicate
were removed for a similar reason: both can be expressed using existing methods, e.g.
sql.assignmentList({
bar: 'baz',
qux: 'quux'
});
becomes:
sql.join([
sql`${sql.identifier(['bar'])} = ${'baz'}`,
sql`${sql.identifier(['qux'])} = ${'quux'}`
], sql`, `)
// of, if identifiers are static, then just:
sql.join([
sql`bar = ${'baz'}`,
sql`qux = ${'quux'}`
], sql`, `)