[storm] Truncating a table

James Henstridge james at jamesh.id.au
Tue Dec 9 23:26:13 GMT 2008


On Mon, Dec 8, 2008 at 9:12 PM, Paul Hummer <paul.hummer at canonical.com> wrote:
> I have a need to basically clear out all the records from a table.  I could
> probably use store.execute, but the reason I'm using an ORM in the first place
> is to avoid writing SQL.  So I have the following code:
>
>        result = self._store.find(FooBarBaz)
>        self._store.rollback()
>
>        for foo in result:
>            self._store.remove(foo)
>            self._store.commit()
>
> This raises a 'OperationalError : database is locked' on a sqlite database.
> There are no other operations going on in this instance, so I'm not sure what's
> going on.
>
> This is using storm 0.12.  Is there a way that I can debug this and see what's
> really going on?

You can delete all records from a table with the following:

    store.find(FooBarBaz).remove()

This will work for simple find expressions: it won't work if you have
any joins (yet).

James.



More information about the storm mailing list