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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#affectedInteger (readonly)

Returns number of affected rows.

Returns:

  • (Integer)

    number of affected rows


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

alias_native :affected, :rowsAffected

#databaseSQL (readonly)

Returns the database the result came from.

Returns:

  • (SQL)

    the database the result came from


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

def database
  @database
end

#lengthInteger (readonly)

Returns number of rows in the result.

Returns:

  • (Integer)

    number of rows in the result


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

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

#transactionTransaction (readonly)

Returns the transaction the result came from.

Returns:

  • (Transaction)

    the transaction the result came from


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.

Parameters:

  • index (Integer)

    the index for the row

Returns:


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:

Returns:

  • (self)

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