mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Make good use of the visitor pattern
This commit is contained in:
1 parent
4c3029e5c1
commit
90f2642ec6
63 files changed
+2391
-1481
No files matched your search
@@ -0,0 +1,26 @@
|
||||
extension SQLCollection {
|
||||
/// Returns an SQL string that represents the collection.
|
||||
///
|
||||
/// - parameter context: An SQL generation context which accepts
|
||||
/// statement arguments.
|
||||
func collectionSQL(_ context: SQLGenerationContext) throws -> String {
|
||||
var generator = SQLCollectionGenerator(context: context)
|
||||
try _accept(&generator)
|
||||
return generator.resultSQL
|
||||
}
|
||||
}
|
||||
|
||||
private struct SQLCollectionGenerator: _SQLCollectionVisitor {
|
||||
let context: SQLGenerationContext
|
||||
var resultSQL = ""
|
||||
|
||||
mutating func visit(_ collection: _SQLExpressionsArray) throws {
|
||||
resultSQL = try collection.expressions
|
||||
.map { try $0.expressionSQL(context, wrappedInParenthesis: false) }
|
||||
.joined(separator: ", ")
|
||||
}
|
||||
|
||||
mutating func visit<Request: SQLRequestProtocol>(_ request: Request) throws {
|
||||
resultSQL = try request.requestSQL(context, forSingleResult: false)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user