Created
October 21, 2017 12:08
-
-
Save neoneye/8e75ce55705ccf0b69148caa07a4084d to your computer and use it in GitHub Desktop.
Unsuccessful experiments getting transactions working with StORM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PerfectPostgreSQL | |
import PostgresStORM | |
import StORM | |
extension PostgresStORM { | |
static func doWithTransaction<Result>(closure: () throws -> Result) throws -> Result { | |
let thisConnection = PostgresConnect( | |
host: PostgresConnector.host, | |
username: PostgresConnector.username, | |
password: PostgresConnector.password, | |
database: PostgresConnector.database, | |
port: PostgresConnector.port | |
) | |
thisConnection.open() | |
if thisConnection.state == .bad { | |
throw StORMError.error("Connection Error") | |
} | |
do { | |
let result: Result = try thisConnection.server.doWithTransaction(closure: closure) | |
thisConnection.server.close() | |
return result | |
} catch { | |
thisConnection.server.close() | |
throw error | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment