Class: Browser::Database::SQL::Result

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Native::Wrapper
Defined in:
opal/browser/database/sql.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#affectedInteger (readonly)



190
# File 'opal/browser/database/sql.rb', line 190

alias_native :affected, :rowsAffected

#databaseSQL (readonly)



138
139
140
# File 'opal/browser/database/sql.rb', line 138

def database
  @database
end

#lengthInteger (readonly)



184
185
186
# File 'opal/browser/database/sql.rb', line 184

def length
  `#@native.rows.length`
end

#transactionTransaction (readonly)



135
136
137
# File 'opal/browser/database/sql.rb', line 135

def transaction
  @transaction
end

Instance Method Details

#[](index) ⇒ Row

Get a row from the result.



155
156
157
158
159
160
161
162
163
# File 'opal/browser/database/sql.rb', line 155

def [](index)
  if index < 0
    index += length
  end

  unless index < 0 || index >= length
    Row.new(`#@native.rows.item(index)`)
  end
end

#each {|row| ... } ⇒ self

Enumerate over the rows.

Yield Parameters:



170
171
172
173
174
175
176
177
178
179
180
# File 'opal/browser/database/sql.rb', line 170

def each(&block)
  return enum_for :each unless block

  %x{
    for (var i = 0, length = #@native.rows.length; i < length; i++) {
      #{block.call(self[`i`])};
    }
  }

  self
end