Skip to content

SQL statements represented in PonyORM

Luckydonald edited this page Dec 8, 2016 · 10 revisions

This pages lists some commonly used SQL stuff, and how that would work with pony. Feel free to improve this list yourself!

DELETE

by query
delete(o for o in Order if o.status == 'CANCELLED')

Pony Docs

with existing instance
user = User.get(id=1234)
user.delete()

Pony Docs

NOT CONFIRMED WORKING:

Or with an instance:

user = User.get(id=1234) User.delete(user)



[Postgres Docs](https://www.postgresql.org/docs/8.3/static/sql-delete.html)


### `LIMIT 50`
```python
.limit(50)

Postgres Docs

OFFSET 100

.limit(50, offset=100)

Postgres Docs

UNIQUE ("a", "b")

class Example(db.Entity):
    a = Required(str)
    b = Optional(int)
    composite_key(a, b)

Pony Docs

lower(column) Lowercase text column

select(
  t in Tag if t.column.lower() == "TestText".lower()
)

Postgres Docs