[storm] dicts and things
James Henstridge
james at jamesh.id.au
Wed Mar 12 06:37:36 GMT 2008
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.
More information about the storm
mailing list