Class: Baza::Driver::Mysql::Result
- Inherits:
-
ResultBase
- Object
- ResultBase
- Baza::Driver::Mysql::Result
- Defined in:
- lib/baza/drivers/mysql/result.rb
Overview
This class controls the results for the normal MySQL-driver.
Constant Summary collapse
- INT_TYPES =
{ ::Mysql::Field::TYPE_DECIMAL => true, ::Mysql::Field::TYPE_TINY => true, ::Mysql::Field::TYPE_LONG => true, ::Mysql::Field::TYPE_YEAR => true }
- FLOAT_TYPES =
{ ::Mysql::Field::TYPE_DECIMAL => true, ::Mysql::Field::TYPE_FLOAT => true, ::Mysql::Field::TYPE_DOUBLE => true }
- TIME_TYPES =
{ ::Mysql::Field::TYPE_DATETIME => true }
- DATE_TYPES =
{ ::Mysql::Field::TYPE_DATE => true }
Instance Method Summary collapse
-
#each ⇒ Object
Loops over every result yielding it.
-
#fetch ⇒ Object
Returns a single result as a hash with symbols as keys.
-
#initialize(driver, result) ⇒ Result
constructor
Constructor.
Methods inherited from ResultBase
Constructor Details
#initialize(driver, result) ⇒ Result
Constructor. This should not be called manually.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/baza/drivers/mysql/result.rb', line 22 def initialize(driver, result) @driver = driver @result = result @mutex = Mutex.new @type_translation = driver.baza.opts[:type_translation] return unless @result @keys = [] @types = [] if @type_translation @result.fetch_fields.each do |key| @keys << key.name.to_sym @types << key.type if @type_translation end end |
Instance Method Details
#each ⇒ Object
Loops over every result yielding it.
58 59 60 61 62 |
# File 'lib/baza/drivers/mysql/result.rb', line 58 def each while data = fetch yield data end end |
#fetch ⇒ Object
Returns a single result as a hash with symbols as keys.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/baza/drivers/mysql/result.rb', line 40 def fetch fetched = nil @mutex.synchronize do fetched = @result.fetch_row end return false unless fetched if @type_translation == true fetched.collect!.with_index do |value, count| translate_value_to_type(value, @types[count]) end end Hash[*@keys.zip(fetched).flatten] end |