Class: ActiveRecord::ConnectionAdapters::WasmSqlite3Adapter::Statement
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::WasmSqlite3Adapter::Statement
- Defined in:
- lib/generators/wasm_rails/install/templates/wasm_sqlite3_adapter.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
-
#bind_params(*params) ⇒ Object
Substitute bound parameters into the SQL (? placeholders).
- #close ⇒ Object
- #column_count ⇒ Object
- #execute ⇒ Object
-
#initialize(js_interface, sql) ⇒ Statement
constructor
A new instance of Statement.
- #reset! ⇒ Object
- #step ⇒ Object
- #to_a ⇒ Object
-
#types ⇒ Object
nil → default type.
Constructor Details
#initialize(js_interface, sql) ⇒ Statement
Returns a new instance of Statement.
69 70 71 72 73 74 75 76 |
# File 'lib/generators/wasm_rails/install/templates/wasm_sqlite3_adapter.rb', line 69 def initialize(js_interface, sql) @js = js_interface @base_sql = sql.to_s @sql = @base_sql @executed = false @columns = [] @rows = [] end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
67 68 69 |
# File 'lib/generators/wasm_rails/install/templates/wasm_sqlite3_adapter.rb', line 67 def columns @columns end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
67 68 69 |
# File 'lib/generators/wasm_rails/install/templates/wasm_sqlite3_adapter.rb', line 67 def rows @rows end |
Instance Method Details
#bind_params(*params) ⇒ Object
Substitute bound parameters into the SQL (? placeholders).
79 80 81 82 83 84 85 86 87 |
# File 'lib/generators/wasm_rails/install/templates/wasm_sqlite3_adapter.rb', line 79 def bind_params(*params) params = params.flatten(1) return if params.empty? i = -1 @sql = @base_sql.gsub('?') do i += 1 quote_value(params[i]) end end |
#close ⇒ Object
116 |
# File 'lib/generators/wasm_rails/install/templates/wasm_sqlite3_adapter.rb', line 116 def close; end |
#column_count ⇒ Object
113 |
# File 'lib/generators/wasm_rails/install/templates/wasm_sqlite3_adapter.rb', line 113 def column_count = (execute; @columns.size) |
#execute ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/generators/wasm_rails/install/templates/wasm_sqlite3_adapter.rb', line 94 def execute return if @executed @executed = true res = @js.call(:exec, @sql) @columns = res[:cols].to_a.map(&:to_s) @rows = res[:rows].to_a.map do |row| row.to_a.map do |val| str = val.to_s case val.typeof when 'string' then str when 'boolean' then str == 'true' when 'number' then str.include?('.') ? val.to_f : val.to_i else str == 'null' ? nil : str end end end end |
#reset! ⇒ Object
117 |
# File 'lib/generators/wasm_rails/install/templates/wasm_sqlite3_adapter.rb', line 117 def reset!; @executed = false; @sql = @base_sql; end |
#step ⇒ Object
89 90 91 92 |
# File 'lib/generators/wasm_rails/install/templates/wasm_sqlite3_adapter.rb', line 89 def step execute nil end |
#to_a ⇒ Object
115 |
# File 'lib/generators/wasm_rails/install/templates/wasm_sqlite3_adapter.rb', line 115 def to_a = (execute; @rows) |
#types ⇒ Object
nil → default type
114 |
# File 'lib/generators/wasm_rails/install/templates/wasm_sqlite3_adapter.rb', line 114 def types = (execute; Array.new(@columns.size)) # nil → default type |