[storm] dicts and things
mark.a.brand
mark.a.brand at gmail.com
Wed Mar 12 06:45:54 GMT 2008
thanks.
On 12/03/2008, James Henstridge <james at jamesh.id.au> wrote:
>
> On 12/03/2008, mark. a. brand <mark.a.brand at gmail.com> wrote:
> > hi:
> >
> > *** newbie-alert ***: both python and storm
> >
> > the bit of code below - apparently works in sqlalchemy with sqlalchemy
> > syntax of course.
> >
> > my question is how can i do the same thing in storm, ie create a whole
> bunch
> > or instances at once via a dict.
> >
> > database = create_database("sqlite:hc.db")
> > store = Store(database)
> >
> > class Process(Storm):
> > __storm_table__ = "process"
> > ProcessId = Int(primary = True)
> > Caption = Unicode()
> >
> > store.execute("CREATE TABLE process " "( \
> > ProcessId VARCHAR, \
> > Caption VARCHAR)",
> > noresult = True \
> > )
> >
> > c = wmi.WMI ()
> > for process in c.Win32_Process (['ProcessId', 'Caption']):
> > d = dict ((p, getattr (process, p)) for p in process.properties)
> > Process (**d)
>
>
> You need to add these process objects to the store:
> store.add(Process(**d))
>
>
> > storm.flush()
> > storm.commit()
>
> And this should be store.commit() rather than storm.commit(). You
> should not need the flush() call.
>
>
> James.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/storm/attachments/20080312/512783b7/attachment.htm
More information about the storm
mailing list