Class: Sequel::MySQL::Database
- Inherits:
-
Database
- Object
- Database
- Sequel::MySQL::Database
- Defined in:
- lib/sequel/mysql.rb
Instance Method Summary collapse
- #dataset(opts = nil) ⇒ Object
- #execute(sql) ⇒ Object
- #execute_affected(sql) ⇒ Object
- #execute_insert(sql) ⇒ Object
-
#initialize(opts = {}) ⇒ Database
constructor
A new instance of Database.
- #transaction(&block) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Database
Returns a new instance of Database.
13 14 15 16 17 18 19 |
# File 'lib/sequel/mysql.rb', line 13 def initialize(opts = {}) super @pool.connection_proc = proc do Mysql.real_connect(@opts[:host], @opts[:user], @opts[:password], @opts[:database], @opts[:port]) end end |
Instance Method Details
#dataset(opts = nil) ⇒ Object
21 22 23 |
# File 'lib/sequel/mysql.rb', line 21 def dataset(opts = nil) MySQL::Dataset.new(self, opts) end |
#execute(sql) ⇒ Object
25 26 27 28 29 |
# File 'lib/sequel/mysql.rb', line 25 def execute(sql) @pool.hold do |conn| conn.query(sql) end end |
#execute_affected(sql) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/sequel/mysql.rb', line 38 def execute_affected(sql) @pool.hold do |conn| conn.query(sql) conn.affected_rows end end |
#execute_insert(sql) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/sequel/mysql.rb', line 31 def execute_insert(sql) @pool.hold do |conn| conn.query(sql) conn.insert_id end end |
#transaction(&block) ⇒ Object
45 46 47 |
# File 'lib/sequel/mysql.rb', line 45 def transaction(&block) @pool.hold {|conn| conn.transaction(&block)} end |