[PonyORM-list] How to purge table rows

Alexey Malashkevich alexeymalashkevich at gmail.com
Thu Dec 19 08:34:46 UTC 2013


If I understand correctly you want to purge rows from a table and reset the
table's autoincrement counter. There is no such functionality in Pony yet,
but you can do that manually using raw SQL.

Below is the code for SQLite:

    def purge_table(entity):
        # purge rows from the table
        sql1 = 'delete from "%s"' % entity._table_
        db.execute(sql1)

        # reset the autoincrement counter
        sql2 = "delete from sqlite_sequence where name='%s'" \
                               % entity._table_
        db.execute(sql2)

    purge_table(MaterialTransaction)

In SQLite table names should be in double quotes and strings should be in
single quotes, that is why the queries above use different quotes (
https://www.sqlite.org/lang_keywords.html)

If you're using another database, let us know which one.


On Thu, Dec 19, 2013 at 2:45 AM, Guy Jacks <guy.jacks at gmail.com> wrote:

> I'm currently calling.
>
> db.drop_table(...) and then calling db.create_tables() in order to purge
> all of the data.  I'm using flask so I wrapped my app in the
> with_transaction context.  I'm getting the following error.
>
> https://gist.github.com/anonymous/9005f162fc6f352a73fc
>
> Note, I don't want to delete all the rows because I want to reset the
> auto-increment on the ids.
>
> _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.com
> /ponyorm-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20131219/4850cb13/attachment.html>


More information about the ponyorm-list mailing list