File tree Expand file tree Collapse file tree 4 files changed +45
-0
lines changed
Sources/StructuredQueriesCore
Documentation.docc/Extensions
Tests/StructuredQueriesTests Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 2828
2929- ``jsonArrayLength()``
3030- ``jsonGroupArray(order:filter:)``
31+ - ``jsonPatch(_:)``
3132
3233### Optionality
3334
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff line change @@ -2,6 +2,17 @@ import Foundation
22import StructuredQueriesSupport
33
44extension 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments