piccolo-orm / piccolo

A fast, user friendly ORM and query builder which supports asyncio.
https://piccolo-orm.com/
MIT License
1.45k stars 91 forks source link

Are there constraints #784

Open BezBartek opened 1 year ago

BezBartek commented 1 year ago

Hello, can we define constraints over the table? Similar to Django, I am requesting for:

Check constraints Unique constraints

Thank you!

dantownsend commented 1 year ago

Unique constraints are possible:

class MyTable(Table):
    name = Varchar(unique=True)

We don't currently have unique together constraints, but it's often requested, so I'll add it soon. Likewise with check constraints.

dantownsend commented 1 year ago

You can add them directly to your database using SQL, and it should be OK.

BezBartek commented 1 year ago

@dantownsend Ye, thank you, I did that In the case of Unique constraints, I mean a lack of ability to set a conditional unique constraint, like: Unique application and status when status is pending. I used to write a lot of constraints like that, they are really helpful to prevent any corrupted data in huge complicated systems