From 85792b8293db67e176cdfa0ef4e63bcf3cf9e72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 15 Oct 2023 08:18:36 +0200 Subject: [PATCH] One availability per JSON function --- GRDB/JSON/SQLJSONExpressible.swift | 9 +++++++-- GRDB/JSON/SQLJSONFunctions.swift | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/GRDB/JSON/SQLJSONExpressible.swift b/GRDB/JSON/SQLJSONExpressible.swift index fed63174c..a38895e2f 100644 --- a/GRDB/JSON/SQLJSONExpressible.swift +++ b/GRDB/JSON/SQLJSONExpressible.swift @@ -259,7 +259,6 @@ extension SQLJSONExpressible { } } #else -@available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ extension SQLJSONExpressible { /// The `->>` SQL operator. /// @@ -285,6 +284,7 @@ extension SQLJSONExpressible { /// /// - parameter path: A [JSON path](https://www.sqlite.org/json1.html#path_arguments), /// or an JSON object field label, or an array index. + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public subscript(_ path: some SQLExpressible) -> SQLExpression { .binary(.jsonExtractSQL, sqlExpression, path.sqlExpression) } @@ -312,6 +312,7 @@ extension SQLJSONExpressible { /// Related SQL documentation: /// /// - parameter path: A [JSON path](https://www.sqlite.org/json1.html#path_arguments). + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public func jsonExtract(atPath path: some SQLExpressible) -> SQLExpression { Database.jsonExtract(self, atPath: path) } @@ -333,6 +334,7 @@ extension SQLJSONExpressible { /// Related SQL documentation: /// /// - parameter paths: A collection of [JSON paths](https://www.sqlite.org/json1.html#path_arguments). + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public func jsonExtract(atPaths paths: C) -> SQLExpression where C: Collection, C.Element: SQLExpressible { @@ -363,13 +365,13 @@ extension SQLJSONExpressible { /// /// - parameter path: A [JSON path](https://www.sqlite.org/json1.html#path_arguments), /// or an JSON object field label, or an array index. + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public func jsonRepresentation(atPath path: some SQLExpressible) -> SQLExpression { .binary(.jsonExtractJSON, sqlExpression, path.sqlExpression) } } // TODO: Enable when those apis are ready. -// @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ // extension ColumnExpression where Self: SQLJSONExpressible { // /// Updates a columns with the `JSON_PATCH` SQL function. // /// @@ -383,6 +385,7 @@ extension SQLJSONExpressible { // /// ``` // /// // /// Related SQLite documentation: +// @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ // public func jsonPatch( // with patch: some SQLExpressible) // -> ColumnAssignment @@ -405,6 +408,7 @@ extension SQLJSONExpressible { // /// // /// - Parameters: // /// - paths: A [JSON path](https://www.sqlite.org/json1.html#path_arguments). +// @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ // public func jsonRemove(atPath path: some SQLExpressible) -> ColumnAssignment { // .init(columnName: name, value: Database.jsonRemove(self, atPath: path)) // } @@ -424,6 +428,7 @@ extension SQLJSONExpressible { // /// // /// - Parameters: // /// - paths: A collection of [JSON paths](https://www.sqlite.org/json1.html#path_arguments). +// @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ // public func jsonRemove(atPaths paths: C) // -> ColumnAssignment // where C: Collection, C.Element: SQLExpressible diff --git a/GRDB/JSON/SQLJSONFunctions.swift b/GRDB/JSON/SQLJSONFunctions.swift index 0f172876f..d4bd5ed60 100644 --- a/GRDB/JSON/SQLJSONFunctions.swift +++ b/GRDB/JSON/SQLJSONFunctions.swift @@ -386,7 +386,6 @@ extension Database { } } #else -@available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ extension Database { /// Validates and minifies a JSON string, with the `JSON` SQL function. /// @@ -398,6 +397,7 @@ extension Database { /// ``` /// /// Related SQLite documentation: + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func json(_ value: some SQLExpressible) -> SQLExpression { .function("JSON", [value.sqlExpression]) } @@ -412,6 +412,7 @@ extension Database { /// ``` /// /// Related SQLite documentation: + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonArray(_ values: C) -> SQLExpression where C: Collection, C.Element: SQLExpressible { @@ -428,6 +429,7 @@ extension Database { /// ``` /// /// Related SQLite documentation: + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonArray(_ values: C) -> SQLExpression where C: Collection, C.Element == any SQLExpressible { @@ -445,6 +447,7 @@ extension Database { /// ``` /// /// Related SQLite documentation: + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonArrayLength(_ value: some SQLExpressible) -> SQLExpression { .function("JSON_ARRAY_LENGTH", [value.sqlExpression]) } @@ -464,6 +467,7 @@ extension Database { /// - Parameters: /// - value: A JSON array. /// - path: A [JSON path](https://www.sqlite.org/json1.html#path_arguments). + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonArrayLength( _ value: some SQLExpressible, atPath path: some SQLExpressible) @@ -501,6 +505,7 @@ extension Database { /// - Parameters: /// - value: A JSON value. /// - path: A [JSON path](https://www.sqlite.org/json1.html#path_arguments). + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonExtract(_ value: some SQLExpressible, atPath path: some SQLExpressible) -> SQLExpression { .function("JSON_EXTRACT", [value.sqlExpression, path.sqlExpression]) } @@ -519,6 +524,7 @@ extension Database { /// - Parameters: /// - value: A JSON value. /// - paths: A collection of [JSON paths](https://www.sqlite.org/json1.html#path_arguments). + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonExtract(_ value: some SQLExpressible, atPaths paths: C) -> SQLExpression where C: Collection, C.Element: SQLExpressible @@ -541,6 +547,7 @@ extension Database { /// - value: A JSON value. /// - assignments: A collection of key/value pairs, where keys are /// [JSON paths](https://www.sqlite.org/json1.html#path_arguments). + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonInsert( _ value: some SQLExpressible, _ assignments: C) @@ -568,6 +575,7 @@ extension Database { /// - value: A JSON value. /// - assignments: A collection of key/value pairs, where keys are /// [JSON paths](https://www.sqlite.org/json1.html#path_arguments). + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonReplace( _ value: some SQLExpressible, _ assignments: C) @@ -595,6 +603,7 @@ extension Database { /// - value: A JSON value. /// - assignments: A collection of key/value pairs, where keys are /// [JSON paths](https://www.sqlite.org/json1.html#path_arguments). + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonSet( _ value: some SQLExpressible, _ assignments: C) @@ -630,6 +639,7 @@ extension Database { /// ``` /// /// Related SQLite documentation: + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonObject(_ elements: C) -> SQLExpression where C: Collection, @@ -650,6 +660,7 @@ extension Database { /// ``` /// /// Related SQLite documentation: + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonPatch( _ value: some SQLExpressible, with patch: some SQLExpressible) @@ -672,6 +683,7 @@ extension Database { /// - Parameters: /// - value: A JSON value. /// - paths: A [JSON path](https://www.sqlite.org/json1.html#path_arguments). + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonRemove(_ value: some SQLExpressible, atPath path: some SQLExpressible) -> SQLExpression { .function("JSON_REMOVE", [value.sqlExpression, path.sqlExpression]) } @@ -690,6 +702,7 @@ extension Database { /// - Parameters: /// - value: A JSON value. /// - paths: A collection of [JSON paths](https://www.sqlite.org/json1.html#path_arguments). + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonRemove(_ value: some SQLExpressible, atPaths paths: C) -> SQLExpression where C: Collection, C.Element: SQLExpressible @@ -707,6 +720,7 @@ extension Database { /// ``` /// /// Related SQLite documentation: + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonType(_ value: some SQLExpressible) -> SQLExpression { .function("JSON_TYPE", [value.sqlExpression]) } @@ -725,6 +739,7 @@ extension Database { /// - Parameters: /// - value: A JSON value. /// - paths: A [JSON path](https://www.sqlite.org/json1.html#path_arguments). + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonType(_ value: some SQLExpressible, atPath path: some SQLExpressible) -> SQLExpression { .function("JSON_TYPE", [value.sqlExpression, path.sqlExpression]) } @@ -739,6 +754,7 @@ extension Database { /// ``` /// /// Related SQLite documentation: + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonIsValid(_ value: some SQLExpressible) -> SQLExpression { .function("JSON_VALID", [value.sqlExpression]) } @@ -756,6 +772,7 @@ extension Database { /// ``` /// /// Related SQLite documentation: + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonQuote(_ value: some SQLExpressible) -> SQLExpression { .function("JSON_QUOTE", [value.sqlExpression.jsonBuilderExpression]) } @@ -763,6 +780,7 @@ extension Database { /// The `JSON_GROUP_ARRAY` SQL function. /// /// Related SQLite documentation: + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonGroupArray(_ value: some SQLExpressible) -> SQLExpression { .function("JSON_GROUP_ARRAY", [value.sqlExpression.jsonBuilderExpression]) } @@ -770,6 +788,7 @@ extension Database { /// The `JSON_GROUP_OBJECT` SQL function. /// /// Related SQLite documentation: + @available(iOS 16, macOS 13.2, tvOS 17, watchOS 9, *) // SQLite 3.38+ public static func jsonGroupObject(key: some SQLExpressible, value: some SQLExpressible) -> SQLExpression { .function("JSON_GROUP_OBJECT", [key.sqlExpression, value.sqlExpression.jsonBuilderExpression]) }