Module: Swift
- Defined in:
- lib/swift.rb,
lib/swift/type.rb,
lib/swift/header.rb,
lib/swift/record.rb,
lib/swift/result.rb,
lib/swift/adapter.rb,
lib/swift/version.rb,
lib/swift/attribute.rb,
lib/swift/statement.rb,
lib/swift/migrations.rb,
lib/swift/adapter/sql.rb,
lib/swift/validations.rb,
lib/swift/identity_map.rb,
lib/swift/adapter/mysql.rb,
lib/swift/adapter/sqlite3.rb,
lib/swift/adapter/em/mysql.rb,
lib/swift/adapter/postgres.rb,
lib/swift/adapter/synchrony.rb,
lib/swift/adapter/em/postgres.rb,
lib/swift/adapter/eventmachine.rb,
lib/swift/fiber_connection_pool.rb,
lib/swift/adapter/synchrony/mysql.rb,
lib/swift/adapter/synchrony/postgres.rb
Overview
Based on EM::Synchrony::ConnectionPool
Defined Under Namespace
Modules: Migrations, Type Classes: Adapter, Attribute, Error, Errors, FiberConnectionPool, Header, IdentityMap, Record, Result, RuntimeError, Statement
Constant Summary collapse
- VERSION =
'1.2.3'
Class Method Summary collapse
-
.db(name = nil, &block) ⇒ Swift::Adapter
Fetch or scope a block to a specific DB by name.
-
.migrate!(name = nil) ⇒ Object
Migrations.
- .repositories ⇒ Object
-
.schema ⇒ Array<Swift::Schema>
List of known Swift::Schema classes.
- .scopes ⇒ Object
-
.setup(name, type = nil, options = {}) ⇒ Swift::Adapter
Setup a new DB connection.
-
.trace(io = $stdout, &block) ⇒ Object
Trace the command execution in currently scoped adapter.
Class Method Details
.db(name = nil, &block) ⇒ Swift::Adapter
Fetch or scope a block to a specific DB by name.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/swift.rb', line 98 def db name = nil, &block repository = name || scopes.size < 1 ? repositories[name ||= :default] : scopes.last repository or raise "Unknown db '#{name}', did you forget to #setup ?" if block_given? begin scopes.push(repository) block.call(repository) ensure scopes.pop end end repository end |
.migrate!(name = nil) ⇒ Object
Migrations
47 48 49 |
# File 'lib/swift/migrations.rb', line 47 def self.migrate! name = nil schema.each {|record| record.migrate!(db(name))} end |
.repositories ⇒ Object
133 134 135 |
# File 'lib/swift.rb', line 133 def repositories @repositories ||= {} end |
.schema ⇒ Array<Swift::Schema>
List of known Swift::Schema classes.
Handy if you are brewing stuff like migrations and need a list of defined schema subclasses.
118 119 120 |
# File 'lib/swift.rb', line 118 def schema @schema ||= [] end |
.scopes ⇒ Object
138 139 140 |
# File 'lib/swift.rb', line 138 def scopes Thread.current[:swift_db] ||= [] end |
.setup(name, type = nil, options = {}) ⇒ Swift::Adapter
Setup a new DB connection.
You almost certainly want to setup a :default
named adapter. The :default
scope will be used for unscoped calls to Swift.db
.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/swift.rb', line 71 def setup name, type = nil, = {} if block_given? repositories[name] = yield else unless type.kind_of?(Class) && type < Swift::Adapter raise TypeError, "Expected +type+ Swift::Adapter subclass but got #{type.inspect}" end repositories[name] = type.new() end end |