Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
helje5 committed Apr 17, 2023
2 parents adba58c + ecd2a08 commit e69012a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions Sources/Lighter/Expression/SQLBuilder.swift
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down Expand Up @@ -42,9 +46,19 @@ public struct SQLBuilder<Base: SQLRecord> {
/// 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
}


Expand Down
4 changes: 2 additions & 2 deletions Sources/Lighter/Lighter.docc/Linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand All @@ -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: [
Expand Down

0 comments on commit e69012a

Please sign in to comment.