diff --git a/Sources/SQLite/Typed/Expression.swift b/Sources/SQLite/Typed/Expression.swift index 95cdd3b9..b1c5ea4a 100644 --- a/Sources/SQLite/Typed/Expression.swift +++ b/Sources/SQLite/Typed/Expression.swift @@ -106,6 +106,9 @@ extension ExpressionType { " ".join([self, Expression(literal: "DESC")]) } + public func alias(_ aliasName: String) -> Expressible { + return " ".join([self, Expression(literal: "AS \"\(aliasName)\"")]) + } } extension ExpressionType where UnderlyingType: Value { diff --git a/Sources/SQLite/Typed/Query.swift b/Sources/SQLite/Typed/Query.swift index 2d88db63..1323bb17 100644 --- a/Sources/SQLite/Typed/Query.swift +++ b/Sources/SQLite/Typed/Query.swift @@ -1137,7 +1137,7 @@ public struct Row { fileprivate let values: [Binding?] - internal init(_ columnNames: [String: Int], _ values: [Binding?]) { + public init(_ columnNames: [String: Int], _ values: [Binding?]) { self.columnNames = columnNames self.values = values } @@ -1169,7 +1169,7 @@ public struct Row { } guard let idx = columnNames[column.template] else { - let similar = Array(columnNames.keys).filter { $0.hasSuffix(".\(column.template)") } + let similar = Array(columnNames.keys).filter { $0.hasSuffix(".\(column.template)") || $0.hasSuffix(" AS \(column.template)") } switch similar.count { case 0: @@ -1228,21 +1228,21 @@ public enum OnConflict: String { public struct QueryClauses { - var select = (distinct: false, columns: [Expression(literal: "*") as Expressible]) + public internal(set) var select = (distinct: false, columns: [Expression(literal: "*") as Expressible]) - var from: (name: String, alias: String?, database: String?) + public internal(set) var from: (name: String, alias: String?, database: String?) - var join = [(type: JoinType, query: QueryType, condition: Expressible)]() + public internal(set) var join = [(type: JoinType, query: QueryType, condition: Expressible)]() - var filters: Expression? + public internal(set) var filters: Expression? - var group: (by: [Expressible], having: Expression?)? + public internal(set) var group: (by: [Expressible], having: Expression?)? - var order = [Expressible]() + public internal(set) var order = [Expressible]() - var limit: (length: Int, offset: Int?)? + public internal(set) var limit: (length: Int, offset: Int?)? - var union = [QueryType]() + public internal(set) var union = [QueryType]() fileprivate init(_ name: String, alias: String?, database: String?) { from = (name, alias, database)