[storm] How to convert a resultset into a dictionary?

R Pish rpishcr at gmail.com
Sun Apr 13 16:40:21 UTC 2014


Thanks Oscar!

Your example worked perfectly. Now I am thinking on making a method in the
User model called something like "asdictionary()" which I would call to get
the dictionary version of a particular User object -of course without the
references, I would have to investigate how to get the references and push
them into the dictionary-.

So, another question came up; there is a datetime column called "updated"
in the User model, with this code, if I access user_array["updated"] I get
this:

'updated': datetime.datetime(2014, 4, 13, 10, 24, 28)  (which is not json
serializable)

but if I access user.updated I will get: '2014-04-13 10:24:28' (which is
json serializable)

Certainly I would have to convert the "dict" version to its corresponding
datetime string representation to make it json serializable, but I wanted
to know if there is something inside Storm that I would use to make this
conversion?

Thanks again.
Kind regards.



2014-04-13 10:12 GMT-06:00 Oscar Campos <oscar.campos at member.fsf.org>:

> Hi.
>
> Let's say that you have an User model:
>
> user = store.find(User, User.email == 'rpishcr at gmail.com').one()
> user_array = dict([(p.name, getattr(user, (p.name))) for p in
> user._storm_columns.values()])
>
> Take into consideration that the former will work for simple properties,
> meaning that no references will be convert and returned as dictionary.
>
> Regards
>
> --
> Join the free software foundation and become free as in freedom
>
> On 13 April 2014 at 07:37:08, R Pish (rpishcr at gmail.com) wrote:
>
> Hi,
>
> What is the recommended way to convert a resultset produced by a call
> like: store.find(User, User.id == myvarid).one() ?
>
> Thanks in advance
>  --
> storm mailing list
> storm at lists.canonical.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/storm
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/storm/attachments/20140413/b3a18dad/attachment.html>


More information about the storm mailing list