lib/baza/drivers/sqlite3/result.rb in baza-0.0.19 vs lib/baza/drivers/sqlite3/result.rb in baza-0.0.20
- old
+ new
@@ -6,31 +6,30 @@
begin
@statement.execute
@type_translation = driver.baza.opts[:type_translation]
@types = statement.types if @type_translation == true
- @columns = statement.columns.map { |column| column.to_sym }
+ @columns = statement.columns.map(&:to_sym)
read_results
@index = -1
ensure
@statement.close
end
end
# Returns a single result.
def fetch
row = @results[@index += 1]
+ return unless row
- if row
- if @types
- row.map!.with_index { |value, index| translate_type(value, @types[index]) } if @types
- elsif @type_translation == :string
- row.map! { |value| value.to_s }
- end
-
- return Hash[*@columns.zip(row).flatten]
+ if @types
+ row.map!.with_index { |value, index| translate_type(value, @types[index]) } if @types
+ elsif @type_translation == :string
+ row.map!(&:to_s)
end
+
+ Hash[*@columns.zip(row).flatten]
end
# Loops over every result yielding them.
def each
while data = fetch
@@ -49,16 +48,16 @@
@results << row
end
end
def translate_type(value, type)
- if value
- if type == 'datetime'
- return Time.parse(value)
- elsif type == 'date'
- return Date.parse(value)
- else
- return value
- end
+ return unless value
+
+ if type == "datetime"
+ Time.parse(value)
+ elsif type == "date"
+ Date.parse(value)
+ else
+ value
end
end
end