Skip to content

Commit ddaa35e

Browse files
authored
Reduce number of query fragment segments (#144)
We should only introduce non-empty segments.
1 parent 3616df2 commit ddaa35e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/StructuredQueriesCore/QueryFragment.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ extension QueryFragment: ExpressibleByStringInterpolation {
150150
}
151151

152152
public mutating func appendLiteral(_ literal: String) {
153+
guard !literal.isEmpty else { return }
153154
segments.append(.sql(literal))
154155
}
155156

@@ -183,7 +184,7 @@ extension QueryFragment: ExpressibleByStringInterpolation {
183184
///
184185
/// - Parameter sql: A raw query string.
185186
public mutating func appendInterpolation(raw sql: String) {
186-
segments.append(.sql(sql))
187+
appendLiteral(sql)
187188
}
188189

189190
/// Append a raw lossless string to the interpolation.
@@ -200,7 +201,7 @@ extension QueryFragment: ExpressibleByStringInterpolation {
200201
///
201202
/// - Parameter sql: A raw query string.
202203
public mutating func appendInterpolation(raw sql: some LosslessStringConvertible) {
203-
segments.append(.sql(sql.description))
204+
appendLiteral(sql.description)
204205
}
205206

206207
/// Append a query binding to the interpolation.

0 commit comments

Comments
 (0)