Class: NeverBlock::DB::Mysql
- Inherits:
-
Mysql
- Object
- Mysql
- NeverBlock::DB::Mysql
- Defined in:
- lib/neverblock/io/db/drivers/mysql.rb
Overview
A modified mysql connection driver. It builds on the original pg driver. This driver is able to register the socket at a certain backend (EM) and then whenever the query is executed within the scope of a friendly fiber. It will be done in async mode and the fiber will yield
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(*args) ⇒ Mysql
constructor
Initializes the connection and remembers the connection params.
-
#query(sql) ⇒ Object
(also: #exec)
Assuming the use of NeverBlock fiber extensions and that the exec is run in the context of a fiber.
-
#real_connect(*args) ⇒ Object
(also: #connect)
Does a normal real_connect if arguments are passed.
Constructor Details
#initialize(*args) ⇒ Mysql
Initializes the connection and remembers the connection params
19 20 21 22 |
# File 'lib/neverblock/io/db/drivers/mysql.rb', line 19 def initialize(*args) @connection_params = args super(*@connection_params) end |
Instance Method Details
#query(sql) ⇒ Object Also known as: exec
Assuming the use of NeverBlock fiber extensions and that the exec is run in the context of a fiber. One that have the value :neverblock set to true. All neverblock IO classes check this value, setting it to false will force the execution in a blocking way.
37 38 39 40 41 42 43 44 45 |
# File 'lib/neverblock/io/db/drivers/mysql.rb', line 37 def query(sql) if NB.neverblocking? && NB.reactor.running? send_query sql NB.wait(:read, IO.new(socket)) get_result else super(sql) end end |
#real_connect(*args) ⇒ Object Also known as: connect
Does a normal real_connect if arguments are passed. If no arguments are passed it uses the ones it remembers
26 27 28 29 |
# File 'lib/neverblock/io/db/drivers/mysql.rb', line 26 def real_connect(*args) @connection_params = args unless args.empty? super(*@connection_params) end |