diff --git a/Sources/Lighter/Expression/SQLBuilder.swift b/Sources/Lighter/Expression/SQLBuilder.swift index a086259..ca9fe24 100644 --- a/Sources/Lighter/Expression/SQLBuilder.swift +++ b/Sources/Lighter/Expression/SQLBuilder.swift @@ -1,8 +1,12 @@ // // Created by Helge Heß. -// Copyright © 2022 ZeeZide GmbH. +// Copyright © 2022-2023 ZeeZide GmbH. // +#if canImport(Foundation) + import Foundation +#endif + /** * A helper struct to build SQL queries. */ @@ -42,9 +46,19 @@ public struct SQLBuilder { /// Escape the `id` (e.g. a column or table name) and surround it by quotes. @inlinable public func escapeAndQuoteIdentifier(_ id: String) -> String { - id.contains("\"") - ? "\"\(id.replacingOccurrences(of: "\"", with: "\"\""))\"" - : "\"\(id)\"" + guard id.contains("\"") else { return "\"\(id)\"" } + + #if canImport(Foundation) + return "\"\(id.replacingOccurrences(of: "\"", with: "\"\""))\"" + #else + if #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) { + // Tie to Swift version on Linux? + return id.replacing("\"", with: "\"\"") + } + else { + fatalError("Can't escape identifier w/o Foundation.") + } + #endif } diff --git a/Sources/Lighter/Lighter.docc/Linux.md b/Sources/Lighter/Lighter.docc/Linux.md index e5928db..f3610cc 100644 --- a/Sources/Lighter/Lighter.docc/Linux.md +++ b/Sources/Lighter/Lighter.docc/Linux.md @@ -35,7 +35,7 @@ import Northwind // @Lighter-swift/NorthwindSQLite.swift let db = Northwind.module! let app = express() -app.get("/api/products") { _, res, _ in +app.get("/api/products") { _, res in res.send(try db.products.fetch()) } @@ -60,7 +60,7 @@ var package = Package( .package(url: "https://Lighter-swift/NorthwindSQLite.swift.git", from: "1.0.0"), .package(url: "https://github.com/Macro-swift/MacroExpress.git", - from: "0.8.8") + from: "1.0.2") ], targets: [