Class: SQLite::Recordsets

Inherits:
Object
  • Object
show all
Defined in:
lib/sqlite.rb

Overview

Used to serialize/deserialize Recordsets over AMQP message payloads

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(binary = nil) ⇒ Recordsets

Returns a new instance of Recordsets.

Parameters:

  • (defaults to: nil)

    Optional MesagePack payload. Will deserialize if provided.



215
216
217
218
219
220
221
222
# File 'lib/sqlite.rb', line 215

def initialize(binary = nil)
  @headers    = {}
  @recordsets = []

  if not binary.nil?
    from_mpack binary
  end
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



212
213
214
# File 'lib/sqlite.rb', line 212

def headers
  @headers
end

#recordsetsObject

Returns the value of attribute recordsets.



212
213
214
# File 'lib/sqlite.rb', line 212

def recordsets
  @recordsets
end

Instance Method Details

#<<(element) ⇒ Object



224
225
226
227
228
229
230
# File 'lib/sqlite.rb', line 224

def <<(element)
  if element.class != Recordset
    raise "Invalide element type. Must be Recordset"
  end

  @recordsets << element
end

#fromMsgPack(binary) ⇒ Object

Deserilize MessagePack payload

Parameters:

  • MesagePack payload. Will deserialize if provided.



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/sqlite.rb', line 246

def fromMsgPack(binary)
  @recordsets = []

  data = MessagePack.unpack(binary)

  if data[0].class != Hash or data[1].class != Array
    raise "Invalid messagepack format"
  end

  @headers = data[0]

  # Convert raw recordset format into Ruby Recordset classes
  data[1].each do |rs|
    recordset = Recordset.new()
    recordset.load(rs)
    @recordsets << recordset      
  end
end

#toMsgPackObject

Serilize MessagePack payload

Returns:

  • Returns the serialized data in MessagePack binary format



234
235
236
237
238
239
240
241
242
# File 'lib/sqlite.rb', line 234

def toMsgPack()
  # Convert Ruby Recordset instances to raw array format (JSON-like)
  recordsets = []
  @recordsets.each do |recordset|
    recordsets << [recordset.columns, recordset.types, recordset.rows]
  end

  return MessagePack.pack([@headers, recordsets])
end