Sha256: 7f2dfb1379f847d0d917ceea9d9c726ca774c3744af1fd6dac92c669969ad27d
Contents?: true
Size: 1.01 KB
Versions: 4
Compression:
Stored size: 1.01 KB
Contents
# -*- coding: utf-8 -*- require 'sinatra/base' require 'sequel' module Sinatra # wrap routed request with sequel transaction block. # note: this is NOT thread safe. please ensure not to be used in the # multi-threaded apps. module SequelTransaction module Helpers # TODO: abstract database connection. it means that do not use # Sequel::DATABASE.first where to get the connection. public # commit manually before return from the request block def commit_transaction db = Sequel::DATABASES.first db << db.__send__(:commit_transaction_sql) end private def route_eval(&block) db = Sequel::DATABASES.first begin db.transaction do super(&block) end rescue Sequel::DatabaseError, Sequel::DatabaseConnectionError => e db.disconnect raise e end end end def self.registered(app) app.helpers SequelTransaction::Helpers end end end
Version data entries
4 entries across 4 versions & 2 rubygems