Peewee v2.2.0 Release Notes

  • ๐Ÿš€ This release contains a large refactoring of the way SQL was generated for both โšก๏ธ the standard query classes (Select, Insert, Update, Delete) as well as for the DDL methods (create_table, create_index, etc). Instead of joining strings of SQL and manually quoting things, I've created Clause objects containing multiple Node objects to represent all parts of the query.

    I also changed the way peewee determins the SQL to represent a field. Now a field implements __ddl__ and __ddl_column__ methods. The former creates the entire field definition, e.g.:

    "quoted_column_name" <result of call to __ddl_column__> [NOT NULL/PRIMARY KEY/DEFAULT NEXTVAL(...)/CONSTRAINTS...]
    

    The latter method is responsible just for the column type definition. This might ๐Ÿ‘ return VARCHAR(255) or simply TEXT. I've also added support for arbitrary constraints on each field, so you might have:

    price = DecimalField(decimal_places=2, constraints=[Check('price > 0')])
    

    ๐Ÿ”„ Changes in 2.2.0

    • ๐Ÿ”จ Refactored query generation for both SQL queries and DDL queries.
    • ๐Ÿ‘Œ Support for arbitrary column constraints.
    • โช autorollback option to the Database class that will roll back the transaction before raising an exception.
    • โž• Added JSONField type to the postgresql_ext module.
    • Track fields that are explicitly set, allowing faster saves (thanks @soasme).
    • ๐Ÿ‘ Allow the FROM clause to be an arbitrary Node object (#290).
    • schema is a new Model.Mketa option and is used throughout the code.
    • ๐Ÿ‘ Allow indexing operation on HStore fields (thanks @zdxerr, #293).

    ๐Ÿ› Bugs fixed

    • โšก๏ธ #277 (where calls not chainable with update query)
    • #278, use wraps(), thanks @lucasmarshall
    • #284, call prepared() after create(), thanks @soasme.
    • #286, cursor description issue with pwiz + postgres

    View commits