Class: YeSQL::Bindings::Extract
- Inherits:
-
Object
- Object
- YeSQL::Bindings::Extract
- Includes:
- Common::Adapter
- Defined in:
- lib/yesql/bindings/extract.rb
Instance Method Summary collapse
- #bind_vals ⇒ Object
- #bind_vars ⇒ Object
-
#initialize(hash, indexed_bindings, index, value) ⇒ Extract
constructor
A new instance of Extract.
- #last_val ⇒ Object
- #prev ⇒ Object
Methods included from Common::Adapter
Constructor Details
#initialize(hash, indexed_bindings, index, value) ⇒ Extract
Returns a new instance of Extract.
11 12 13 14 15 16 |
# File 'lib/yesql/bindings/extract.rb', line 11 def initialize(hash, indexed_bindings, index, value) @hash = hash @index = index @indexed_bindings = indexed_bindings @value = value end |
Instance Method Details
#bind_vals ⇒ Object
18 19 20 21 22 |
# File 'lib/yesql/bindings/extract.rb', line 18 def bind_vals return [nil, value] unless array? value.map { |bind| [nil, bind] } end |
#bind_vars ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/yesql/bindings/extract.rb', line 24 def bind_vars if mysql? return "?" unless array? Array.new(size, "?").join(", ") elsif pg? return "$#{last_val}" unless array? value.map.with_index(bind_index) { |_, i| "$#{i}" }.join(", ") end end |
#last_val ⇒ Object
36 37 38 |
# File 'lib/yesql/bindings/extract.rb', line 36 def last_val prev_last_val + current_val_size end |
#prev ⇒ Object
40 41 42 43 44 |
# File 'lib/yesql/bindings/extract.rb', line 40 def prev return if first? indexed_bindings[index - 2].first end |