0001 // Model.swift 0002 // 0003 // The MIT License (MIT) 0004 // 0005 // Copyright (c) 2015 Formbound 0006 // 0007 // Permission is hereby granted, free of charge, to any person obtaining a copy 0008 // of this software and associated documentation files (the "Software"), to deal 0009 // in the Software without restriction, including without limitation the rights 0010 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0011 // copies of the Software, and to permit persons to whom the Software is 0012 // furnished to do so, subject to the following conditions: 0013 // 0014 // The above copyright notice and this permission notice shall be included in all 0015 // copies or substantial portions of the Software. 0016 // 0017 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0018 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0019 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0020 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0021 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0022 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0023 // SOFTWARE. 0024 0025 public protocol ModelFieldset: CustomStringConvertible { 0026 static var tableName
Row.swift:126 public func data<F: ModelFieldset>(field: F) throws -> Data? {Row.swift:130 public func data<F: ModelFieldset>(field: F) throws -> Data {Row.swift:134 public func value<T: ValueConvertible, F: ModelFieldset>(field: F) throws -> T? {Row.swift:138 public func value<T: ValueConvertible, F: ModelFieldset>(field: F) throws -> T {Model.swift:35 public extension ModelFieldset where Self: RawRepresentable, Self.RawValue == String {Model.swift:41 public extension ModelFieldset {Model.swift:72 public func == <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {Model.swift:76 public func == <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:76 public func == <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:80 public func > <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {Model.swift:84 public func > <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:84 public func > <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:89 public func >= <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {Model.swift:93 public func >= <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:93 public func >= <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:98 public func < <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {Model.swift:102 public func < <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:102 public func < <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:107 public func <= <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {Model.swift:111 public func <= <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:111 public func <= <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:115 public func == <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> JoinKey<L, R> {Model.swift:115 public func == <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> JoinKey<L, R> {Model.swift:126 public static func select(fields: ModelFieldset...) -> Select<Self> {Query.swift:78 internal init<L: ModelFieldset, R: Model>(type: JoinType<R>, key: JoinKey<L, R.Field>) {Query.swift:145 public let fields: [ModelFieldset]Query.swift:188 public init(fields: [ModelFieldset]) {Query.swift:192 public init(_ fields: ModelFieldset...) {: String { get } 0027 0028 var qualifiedName
Model.swift:44 return "\(self.dynamicType.tableName).\(unqualifiedName)"Model.swift:48 return "\(self.dynamicType.tableName)__\(unqualifiedName)"Query.swift:58 return "LEFT JOIN \(T.Field.tableName)"Query.swift:60 return "RIGHT JOIN \(T.Field.tableName)"Query.swift:62 return "INNER JOIN \(T.Field.tableName)"Query.swift:64 return "OUTER JOIN \(T.Field.tableName)"Query.swift:94 var statement = Statement(components: ["DELETE", "FROM", ModelType.Field.tableName])Query.swift:123 var statement = Statement(components: ["INSERT INTO", M.Field.tableName], parameters: Array(valuesByFieldName.values))Query.swift:250 var statement = Statement(components: ["SELECT", fieldString, "FROM", ModelType.Field.tableName]): String { get } 0029 0030 var unqualifiedName
Row.swift:135 return try value(field.qualifiedName)Row.swift:139 return try value(field.qualifiedName)Model.swift:52 return qualifiedNameModel.swift:56 return .In(qualifiedName, values)Model.swift:60 return .In(qualifiedName, values)Model.swift:64 return .NotIn(qualifiedName, values)Model.swift:68 return .NotIn(qualifiedName, values)Model.swift:73 return .Equals(lhs.qualifiedName, .Value(rhs))Model.swift:77 return .Equals(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:77 return .Equals(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:81 return .GreaterThan(lhs.qualifiedName, .Value(rhs))Model.swift:85 return .GreaterThan(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:85 return .GreaterThan(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:90 return .GreaterThanOrEquals(lhs.qualifiedName, .Value(rhs))Model.swift:94 return .GreaterThanOrEquals(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:94 return .GreaterThanOrEquals(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:99 return .LessThan(lhs.qualifiedName, .Value(rhs))Model.swift:103 return .LessThan(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:103 return .LessThan(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:108 return .LessThanOrEquals(lhs.qualifiedName, .Value(rhs))Model.swift:112 return .LessThanOrEquals(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:112 return .LessThanOrEquals(lhs.qualifiedName, .Property(rhs.qualifiedName))Query.swift:80 self.leftKey = key.left.qualifiedNameQuery.swift:81 self.rightKey = key.right.qualifiedNameQuery.swift:248 let fieldString = fields.isEmpty ? "*" : fields.map { "\($0.qualifiedName) AS \($0.alias)" }.joinWithSeparator(", "): String { get } 0031 0032 var alias
Model.swift:44 return "\(self.dynamicType.tableName).\(unqualifiedName)"Model.swift:48 return "\(self.dynamicType.tableName)__\(unqualifiedName)"Query.swift:126 "(\(valuesByFieldName.keys.map { $0.unqualifiedName }.joinWithSeparator(", ")))": String { get } 0033 } 0034 0035 public extension ModelFieldset where Self: RawRepresentable, Self.RawValue == String { 0036 public var unqualifiedName: String { 0037 return rawValue 0038 } 0039 } 0040 0041 public extension ModelFieldset { 0042 0043 public var qualifiedName: String { 0044 return "\(self.dynamicType.tableName).\(unqualifiedName)" 0045 } 0046 0047 public var alias: String { 0048 return "\(self.dynamicType.tableName)__\(unqualifiedName)" 0049 } 0050 0051 public var description: String { 0052 return qualifiedName 0053 } 0054 0055 public func containedIn(values: [ValueConvertible?]) -> Condition { 0056 return .In(qualifiedName, values) 0057 } 0058 0059 public func containedIn(values: ValueConvertible?...) -> Condition { 0060 return .In(qualifiedName, values) 0061 } 0062 0063 public func notContainedIn(values: [ValueConvertible?]) -> Condition { 0064 return .NotIn(qualifiedName, values) 0065 } 0066 0067 public func notContainedIn(values: ValueConvertible?...) -> Condition { 0068 return .NotIn(qualifiedName, values) 0069 } 0070 } 0071 0072 public func == <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition { 0073 return .Equals(lhs.qualifiedName, .Value(rhs)) 0074 } 0075 0076 public func == <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition { 0077 return .Equals(lhs.qualifiedName, .Property(rhs.qualifiedName)) 0078 } 0079 0080 public func > <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition { 0081 return .GreaterThan(lhs.qualifiedName, .Value(rhs)) 0082 } 0083 0084 public func > <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition { 0085 return .GreaterThan(lhs.qualifiedName, .Property(rhs.qualifiedName)) 0086 } 0087 0088 0089 public func >= <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition { 0090 return .GreaterThanOrEquals(lhs.qualifiedName, .Value(rhs)) 0091 } 0092 0093 public func >= <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition { 0094 return .GreaterThanOrEquals(lhs.qualifiedName, .Property(rhs.qualifiedName)) 0095 } 0096 0097 0098 public func < <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition { 0099 return .LessThan(lhs.qualifiedName, .Value(rhs)) 0100 } 0101 0102 public func < <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition { 0103 return .LessThan(lhs.qualifiedName, .Property(rhs.qualifiedName)) 0104 } 0105 0106 0107 public func <= <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition { 0108 return .LessThanOrEquals(lhs.qualifiedName, .Value(rhs)) 0109 } 0110 0111 public func <= <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition { 0112 return .LessThanOrEquals(lhs.qualifiedName, .Property(rhs.qualifiedName)) 0113 } 0114 0115 public func == <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> JoinKey<L, R> { 0116 return JoinKey(left: lhs, right: rhs) 0117 } 0118 0119 public protocol Model
Query.swift:248 let fieldString = fields.isEmpty ? "*" : fields.map { "\($0.qualifiedName) AS \($0.alias)" }.joinWithSeparator(", "){ 0120 associatedtype Field
Entity.swift:25 public protocol Entity: Model {Model.swift:125 public extension Model {Query.swift:78 internal init<L: ModelFieldset, R: Model>(type: JoinType<R>, key: JoinKey<L, R.Field>) {Query.swift:161 public func join<T: Model>(type: JoinType<T>, on key: JoinKey<M.Field, T.Field>) -> Select {: ModelFieldset, Hashable 0121 0122 init(row: Row) throws 0123 } 0124 0125 public extension Model { 0126 public static func select(fields: ModelFieldset...) -> Select<Self> { 0127 return Select(fields: fields) 0128 } 0129 0130 public static func insert(valuesByFieldName: [Field: ValueConvertible?]) -> Insert<Self> { 0131 return Insert(valuesByFieldName) 0132 } 0133 } 0134
Entity.swift:29 static var fieldForPrimaryKey: Field { get }Model.swift:130 public static func insert(valuesByFieldName: [Field: ValueConvertible?]) -> Insert<Self> {Query.swift:58 return "LEFT JOIN \(T.Field.tableName)"Query.swift:60 return "RIGHT JOIN \(T.Field.tableName)"Query.swift:62 return "INNER JOIN \(T.Field.tableName)"Query.swift:64 return "OUTER JOIN \(T.Field.tableName)"Query.swift:78 internal init<L: ModelFieldset, R: Model>(type: JoinType<R>, key: JoinKey<L, R.Field>) {Query.swift:94 var statement = Statement(components: ["DELETE", "FROM", ModelType.Field.tableName])Query.swift:108 internal var valuesByFieldName: [M.Field: ValueConvertible?] = [:]Query.swift:110 public func set(field: M.Field, value: ValueConvertible?) -> Insert {Query.swift:116 public init(_ valuesByFieldName: [M.Field: ValueConvertible?]) {Query.swift:123 var statement = Statement(components: ["INSERT INTO", M.Field.tableName], parameters: Array(valuesByFieldName.values))Query.swift:161 public func join<T: Model>(type: JoinType<T>, on key: JoinKey<M.Field, T.Field>) -> Select {Query.swift:161 public func join<T: Model>(type: JoinType<T>, on key: JoinKey<M.Field, T.Field>) -> Select {Query.swift:250 var statement = Statement(components: ["SELECT", fieldString, "FROM", ModelType.Field.tableName])