Class: Swift::Adapter::Sql

Inherits:
Swift::Adapter show all
Extended by:
Forwardable
Includes:
Migrations::InstanceMethods
Defined in:
lib/swift/adapter/sql.rb,
lib/swift/migrations.rb,
lib/swift/fiber_connection_pool.rb

Overview

FiberConnectionPool

Direct Known Subclasses

Mysql, Postgres, Sqlite3

Instance Attribute Summary

Attributes inherited from Swift::Adapter

#db

Instance Method Summary collapse

Methods included from Migrations::InstanceMethods

#migrate!

Methods inherited from Swift::Adapter

#aexecute, #blocking_execute, #create, #delete, #execute, #get, #identity_map, #initialize, #log_command, #pending, #prepare, #trace, #trace?, #update

Constructor Details

This class inherits a constructor from Swift::Adapter

Instance Method Details

#fields(table) ⇒ Object



17
18
19
20
# File 'lib/swift/adapter/sql.rb', line 17

def fields table
  result = execute("select * from #{table} limit 0")
  Hash[result.fields.map(&:to_sym).zip(result.types)]
end

#serialized_transaction(&block) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/swift/fiber_connection_pool.rb', line 81

def serialized_transaction &block
  Swift.scopes.push(self)
  execute('begin')
  res = yield(self)
  execute('commit')
  res
rescue => e
  execute('rollback')
  raise e
ensure
  Swift.scopes.pop
end

#tablesObject

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/swift/adapter/sql.rb', line 13

def tables
  raise NotImplementedError
end

#transaction(*args) ⇒ Object



22
23
24
# File 'lib/swift/adapter/sql.rb', line 22

def transaction *args
  db.transaction(*args) {|db| yield self}
end