Skip to content

Instantly share code, notes, and snippets.

@neoneye
Created October 21, 2017 12:08
Show Gist options
  • Save neoneye/8e75ce55705ccf0b69148caa07a4084d to your computer and use it in GitHub Desktop.
Save neoneye/8e75ce55705ccf0b69148caa07a4084d to your computer and use it in GitHub Desktop.
Unsuccessful experiments getting transactions working with StORM
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