0001 // Connection.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 @_exported import File 0026 @_exported import Log 0027 @_exported import URI 0028 0029 public protocol ConnectionStringConvertible : StringLiteralConvertible { 0030 init(connectionString: String) 0031 0032 var connectionString: String { get } 0033 } 0034 0035 public class ConnectionInfo { 0036 0037 public var user: String? 0038 public var password
Connection.swift:48 self.user = user: String? 0039 public var host
Connection.swift:49 self.password = password: String 0040 public var port
Connection.swift:45 self.host = host: UInt 0041 public var database
Connection.swift:47 self.port = port: String 0042 0043 0044 public init(host: String, database: String, port: UInt, user: String? = nil, password: String? = nil) { 0045 self.host = host 0046 self.database = database 0047 self.port = port 0048 self.user = user 0049 self.password = password 0050 } 0051 } 0052 0053 0054 public protocol Connection
Connection.swift:46 self.database = database{ 0055 associatedtype ConnectionInfoType
Connection.swift:89 public extension Connection {Query.swift:31 public func execute<T: Connection>(connection: T) throws -> T.ResultType {Query.swift:233 public func fetch<T: Connection where T.ResultType.Generator.Element == Row>(connection: T) throws -> [ModelType] {Query.swift:237 public func first<T: Connection where T.ResultType.Generator.Element == Row>(connection: T) throws -> ModelType? {: ConnectionInfo, ConnectionStringConvertible 0056 associatedtype ResultType
Connection.swift:60 var connectionInfo: ConnectionInfoType { get }Connection.swift:84 init(_ connectionInfo: ConnectionInfoType): Result 0057 associatedtype StatusType
Connection.swift:70 func execute(statement: Statement, deadline: Deadline) throws -> ResultTypeConnection.swift:118 public func execute(statement: Statement, deadline: Deadline = never) throws -> ResultType {Connection.swift:122 public func execute(convertible: StatementConvertible, deadline: Deadline = never) throws -> ResultType {Connection.swift:126 public func executeFromFile(atPath path: String, deadline: Deadline = never) throws -> ResultType {Query.swift:31 public func execute<T: Connection>(connection: T) throws -> T.ResultType {Query.swift:233 public func fetch<T: Connection where T.ResultType.Generator.Element == Row>(connection: T) throws -> [ModelType] {Query.swift:237 public func first<T: Connection where T.ResultType.Generator.Element == Row>(connection: T) throws -> ModelType? {0058 associatedtype Error
Connection.swift:66 var status: StatusType { get }: ErrorType 0059 0060 var connectionInfo: ConnectionInfoType { get } 0061 0062 func open() throws 0063 0064 func close() 0065 0066 var status: StatusType { get } 0067 0068 var log: Log? { get set } 0069 0070 func execute(statement: Statement, deadline: Deadline) throws -> ResultType 0071 0072 func begin
Connection.swift:86 var mostRecentError: Error? { get }() throws 0073 0074 func commit
Connection.swift:92 try begin()() throws 0075 0076 func rollback
Connection.swift:96 try commit()() throws 0077 0078 func createSavePointNamed
Connection.swift:99 try rollback()(name: String) throws 0079 0080 func releaseSavePointNamed
Connection.swift:105 try createSavePointNamed(name)(name: String) throws 0081 0082 func rollbackToSavePointNamed
Connection.swift:109 try releaseSavePointNamed(name)Connection.swift:113 try releaseSavePointNamed(name)(name: String) throws 0083 0084 init(_ connectionInfo: ConnectionInfoType) 0085 0086 var mostRecentError: Error? { get } 0087 } 0088 0089 public extension Connection { 0090 0091 public func transaction
Connection.swift:112 try rollbackToSavePointNamed(name)(block: Void throws -> Void) throws { 0092 try begin() 0093 0094 do { 0095 try block() 0096 try commit() 0097 } 0098 catch { 0099 try rollback() 0100 throw error 0101 } 0102 } 0103 0104 public func withSavePointNamed(name: String, block: Void throws -> Void) throws { 0105 try createSavePointNamed(name) 0106 0107 do { 0108 try block() 0109 try releaseSavePointNamed(name) 0110 } 0111 catch { 0112 try rollbackToSavePointNamed(name) 0113 try releaseSavePointNamed(name) 0114 throw error 0115 } 0116 } 0117 0118 public func execute(statement: Statement, deadline: Deadline = never) throws -> ResultType { 0119 return try execute(statement, deadline: deadline) 0120 } 0121 0122 public func execute
MigrationManager.swift:137 try connection.transaction {(convertible: StatementConvertible, deadline: Deadline = never) throws -> ResultType { 0123 return try execute(convertible.statement, deadline: deadline) 0124 } 0125 0126 public func executeFromFile(atPath path: String, deadline: Deadline = never) throws -> ResultType { 0127 return try execute( 0128 Statement(try String(data: File(path: path).read())), 0129 deadline: deadline 0130 ) 0131 } 0132 0133 public func begin() throws { 0134 try execute("BEGIN") 0135 } 0136 0137 public func commit() throws { 0138 try execute("COMMIT") 0139 } 0140 0141 public func rollback() throws { 0142 try execute("ROLLBACK") 0143 } 0144 } 0145
Connection.swift:118 public func execute(statement: Statement, deadline: Deadline = never) throws -> ResultType {