Class: Runivedo::Result
- Inherits:
-
RemoteObject
- Object
- RemoteObject
- Runivedo::Result
- Includes:
- Enumerable
- Defined in:
- lib/runivedo/sql.rb
Constant Summary
Constants inherited from RemoteObject
Runivedo::RemoteObject::OPERATION_ANSWER_CALL, Runivedo::RemoteObject::OPERATION_CALL_ROM, Runivedo::RemoteObject::OPERATION_DELETE, Runivedo::RemoteObject::OPERATION_NOTIFY
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(*args) ⇒ Result
constructor
A new instance of Result.
- #last_inserted_id ⇒ Object
- #num_affected_rows ⇒ Object
Methods inherited from RemoteObject
#call_rom, #close, #closed?, #on, #send_notification
Constructor Details
#initialize(*args) ⇒ Result
Returns a new instance of Result.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/runivedo/sql.rb', line 31 def initialize(*args) super(*args) @rows = Queue.new @record_id = Future.new @n_affected = Future.new self.on('setError') do |msg| err = Runivedo::SqlError.new(msg) @rows << err @record_id.fail(err) @n_affected.fail(err) end # SELECT self.on('setComplete') { complete_futures } self.on('setTuple') { |t| @rows << t } # UPDATE, DELETE, LINK self.on('setNAffectedRecords') { |n| complete_futures(n_affected: n) } # INSERT self.on('setId') { |id| complete_futures(record_id: id) } end |
Instance Method Details
#each(&block) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/runivedo/sql.rb', line 63 def each(&block) while row = @rows.pop raise row if row.is_a? Exception block.call(row) end end |
#last_inserted_id ⇒ Object
59 60 61 |
# File 'lib/runivedo/sql.rb', line 59 def last_inserted_id @record_id.get end |
#num_affected_rows ⇒ Object
55 56 57 |
# File 'lib/runivedo/sql.rb', line 55 def num_affected_rows @n_affected.get end |