[Nitro] Help creating a ObjectGraph adapter for RubyAMF

Jonathan Buch john at oxyliquit.de
Tue May 22 10:56:35 EDT 2007


Hi,

let's hope I can help you out here.


(here be rest of Og setup and Og.start)

> 1: The result class and data structure

Are you sure you want the raw result class?  Wouldn't some kind of Hash,
OpenObject, Struct suffice?

However, this does work with Og.

SomeModel.ogmanager.with_store do |store|
   result = store.query("SELECT")
end

as the result 'data structure' however changes even between databases
(postgresql pure ruby, postgresql extension) I would advise against
that.

# returns an array
result = SomeModel.find() # ask if you need more help with Og queries

> 2: The column names returned in the query

column_names = SomeModel.serializable_attributes

> 3: The row count

row_count = result.size

> 4: The actual returned data

Are you sure you want an array here?  (like in the AR example)

result.inject([]) do |array,some_model|
   array << column_names.inject({}) do |hash,col|
     hash[col] = some_model.send(col)
     hash
   end
end

will produce a big array with hashes inside, adapt as necessary.

I hope that helps!

Jo

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


More information about the Nitro-general mailing list