Skip to content

Commit 4c3a90c

Browse files
authored
Merge branch 'main' into jsongrouparray-filter-fix
2 parents f40940e + ce44aee commit 4c3a90c

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

Sources/StructuredQueriesCore/Documentation.docc/Extensions/QueryExpression.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
2929
- ``jsonArrayLength()``
3030
- ``jsonGroupArray(order:filter:)``
31+
- ``jsonPatch(_:)``
3132
3233
### Optionality
3334

Sources/StructuredQueriesCore/QueryFragment.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,18 @@ extension QueryFragment: ExpressibleByStringInterpolation {
209209
segments.append(.binding(binding))
210210
}
211211

212+
/// Append a query representable output to the interpolation.
213+
///
214+
/// - Parameters:
215+
/// - queryOutput: A query representable output.
216+
/// - representableType: The type of query representation.
217+
public mutating func appendInterpolation<QueryValue: QueryBindable>(
218+
_ queryOutput: QueryValue.QueryOutput,
219+
as representableType: QueryValue.Type
220+
) {
221+
appendInterpolation(QueryValue(queryOutput: queryOutput))
222+
}
223+
212224
/// Append a query fragment to the interpolation.
213225
///
214226
/// - Parameter fragment: A query fragment.

Sources/StructuredQueriesCore/SQLite/JSONFunctions.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ import Foundation
22
import StructuredQueriesSupport
33

44
extension QueryExpression {
5+
/// Passes this expression and the given one to the `json_patch` function.
6+
///
7+
/// - Parameter other: A JSON object to patch this object with.
8+
/// - Returns: A JSON expression of the result of the invoking the `json_patch` function.
9+
public func jsonPatch<QueryOutput: Codable>(
10+
_ other: some QueryExpression<QueryValue>
11+
) -> some QueryExpression<QueryValue>
12+
where QueryValue == _CodableJSONRepresentation<QueryOutput> {
13+
QueryFunction("json_patch", self, other)
14+
}
15+
516
/// Wraps this expression with the `json_array_length` function.
617
///
718
/// ```swift

Tests/StructuredQueriesTests/JSONFunctionsTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,27 @@ extension SnapshotTests {
318318
"""
319319
}
320320
}
321+
322+
@Test func jsonPatch() {
323+
assertQuery(Values(#bind(["a": 1]).jsonPatch(#bind(["b": 2])))) {
324+
"""
325+
SELECT json_patch('{
326+
"a" : 1
327+
}', '{
328+
"b" : 2
329+
}')
330+
"""
331+
} results: {
332+
"""
333+
┌───────────┐
334+
│ [ │
335+
"a": 1, │
336+
"b": 2 │
337+
│ ] │
338+
└───────────┘
339+
"""
340+
}
341+
}
321342
}
322343
}
323344

0 commit comments

Comments
 (0)