Class: QueryKit::Adapters::MySQLAdapter
- Defined in:
- lib/querykit/adapters/mysql_adapter.rb
Instance Method Summary collapse
- #affected_rows ⇒ Object
- #begin_transaction ⇒ Object
- #close ⇒ Object
- #commit ⇒ Object
- #execute(sql, bindings = []) ⇒ Object
-
#initialize(config) ⇒ MySQLAdapter
constructor
A new instance of MySQLAdapter.
- #last_insert_id ⇒ Object
- #rollback ⇒ Object
Constructor Details
#initialize(config) ⇒ MySQLAdapter
Returns a new instance of MySQLAdapter.
8 9 10 11 |
# File 'lib/querykit/adapters/mysql_adapter.rb', line 8 def initialize(config) require 'mysql2' @client = Mysql2::Client.new(config) end |
Instance Method Details
#affected_rows ⇒ Object
23 24 25 |
# File 'lib/querykit/adapters/mysql_adapter.rb', line 23 def affected_rows @last_result ? @last_result.count : 0 end |
#begin_transaction ⇒ Object
27 28 29 |
# File 'lib/querykit/adapters/mysql_adapter.rb', line 27 def begin_transaction @client.query("START TRANSACTION") end |
#close ⇒ Object
39 40 41 |
# File 'lib/querykit/adapters/mysql_adapter.rb', line 39 def close @client.close end |
#commit ⇒ Object
31 32 33 |
# File 'lib/querykit/adapters/mysql_adapter.rb', line 31 def commit @client.query("COMMIT") end |
#execute(sql, bindings = []) ⇒ Object
13 14 15 16 17 |
# File 'lib/querykit/adapters/mysql_adapter.rb', line 13 def execute(sql, bindings = []) stmt = @client.prepare(sql) @last_result = stmt.execute(*bindings) @last_result.map { |row| row } end |
#last_insert_id ⇒ Object
19 20 21 |
# File 'lib/querykit/adapters/mysql_adapter.rb', line 19 def last_insert_id @client.last_id end |
#rollback ⇒ Object
35 36 37 |
# File 'lib/querykit/adapters/mysql_adapter.rb', line 35 def rollback @client.query("ROLLBACK") end |