Skip to content

Releases: coleifer/peewee

3.13.0

06 Dec 01:34
Compare
Choose a tag to compare

CockroachDB support added

This will be a notable release as it adds support for
CockroachDB, a distributed, horizontally-scalable
SQL database.

Other features and fixes

  • Allow FOR UPDATE clause to specify one or more tables (FOR UPDATE OF...).
  • Support for Postgres LATERAL join.
  • Properly wrap exceptions raised during explicit commit/rollback in the appropriate peewee-specific exception class.
  • Capture original exception object and expose it as exc.orig on the wrapped exception.
  • Properly introspect SMALLINT columns in Postgres schema reflection.
  • More flexible handling of passing database-specific arguments to atomic() and transaction() context-manager/decorator.
  • Fix non-deterministic join ordering issue when using the filter() API across several tables (#2063).

View commits

3.12.0

24 Nov 23:58
Compare
Choose a tag to compare
  • Bulk insert (insert_many() and insert_from()) will now return the row count instead of the last insert ID. If you are using Postgres, peewee will continue to return a cursor that provides an iterator over the newly-inserted primary-key values by default. This behavior is being retained by default for compatibility. Postgres users can simply specify an empty returning() call to disable the cursor and retrieve the rowcount instead.
  • Migration extension now supports altering a column's data-type, via the new alter_column_type() method.
  • Added Database.is_connection_usable() method, which attempts to look at the status of the underlying DB-API connection to determine whether the connection is usable.
  • Common table expressions include a materialized parameter, which can be used to control Postgres' optimization fencing around CTEs.
  • Added BloomFilter.from_buffer() method for populating a bloom-filter from the output of a previous call to the to_buffer() method.
  • Fixed APSW extension's commit() and rollback() methods to no-op if the database is in auto-commit mode.
  • Added generate_always= option to the IdentityField (defaults to False).

View commits

3.11.2

24 Sep 15:58
Compare
Choose a tag to compare
  • Implement hash interface for Alias instances, allowing them to be used in multi-source queries.

View commits

3.11.1

23 Sep 14:03
Compare
Choose a tag to compare
  • Fix bug in new _pk / get_id() implementation for models that explicitly have disabled a primary-key.

View commits

3.11.0

19 Sep 11:42
Compare
Choose a tag to compare
  • Fixes #1991. This particular issue involves joining 3 models together in a chain, where the outer two models are empty. Previously peewee would make the middle model an empty model instance (since a link might be needed from the source model to the outermost model). But since both were empty, it is more correct to make the intervening model a NULL value on the foreign-key field rather than an empty instance.
  • An unrelated fix came out of the work on #1991 where hashing a model whose primary-key happened to be a foreign-key could trigger the FK resolution query. This patch fixes the Model._pk and get_id() interfaces so they no longer introduce the possibility of accidentally resolving the FK.
  • Allow Field.contains(), startswith() and endswith() to compare against another column-like object or expression.
  • Workaround for MySQL prior to 8 and MariaDB handling of union queries inside of parenthesized expressions (like IN).
  • Be more permissive in letting invalid values be stored in a field whose type is INTEGER or REAL, since Sqlite allows this.
  • TimestampField resolution cleanup. Now values 0 and 1 will resolve to a timestamp resolution of 1 second. Values 2-6 specify the number of decimal places (hundredths to microsecond), or alternatively the resolution can still be provided as a power of 10, e.g. 10, 1000 (millisecond), 1e6 (microsecond).
  • When self-referential foreign-keys are inherited, the foreign-key on the subclass will also be self-referential (rather than pointing to the parent model).
  • Add TSV import/export option to the dataset extension.
  • Add item interface to the dataset.Table class for doing primary-key lookup, assignment, or deletion.
  • Extend the mysql ReconnectMixin helper to work with mysql-connector.
  • Fix mapping of double-precision float in postgres schema reflection. Previously it mapped to single-precision, now it correctly uses a double.
  • Fix issue where PostgresqlExtDatabase and MySQLConnectorDatabase did not respect the autoconnect setting.

View commits

3.10.0

03 Aug 09:47
Compare
Choose a tag to compare
  • Add a helper to playhouse.mysql_ext for creating Match full-text search expressions.
  • Added date-part properties to TimestampField for accessing the year, month, day, etc., within a SQL expression.
  • Added to_timestamp() helper for DateField and DateTimeField that produces an expression returning a unix timestamp.
  • Add autoconnect parameter to Database classes. This parameter defaults to True and is compatible with previous versions of Peewee, in which executing a query on a closed database would open a connection automatically. To make it easier to catch inconsistent use of the database connection, this behavior can now be disabled by specifying autoconnect=False, making an explicit call to Database.connect() needed before executing a query.
  • Added database-agnostic interface for obtaining a random value.
  • Allow isolation_level to be specified when initializing a Postgres db.
  • Allow hybrid properties to be used on model aliases. Refs #1969.
  • Support aggregates with FILTER predicates on the latest Sqlite.

Changes

  • More aggressively slot row values into the appropriate field when building objects from the database cursor (rather than using whatever cursor.description tells us, which is buggy in older Sqlite).
  • Be more permissive in what we accept in the insert_many() and insert() methods.
  • When implicitly joining a model with multiple foreign-keys, choose the foreign-key whose name matches that of the related model. Previously, this would have raised a ValueError stating that multiple FKs existed.
  • Improved date truncation logic for Sqlite and MySQL to make more compatible with Postgres' date_trunc() behavior. Previously, truncating a datetime to month resolution would return '2019-08' for example. As of 3.10.0, the Sqlite and MySQL date_trunc implementation returns a full datetime, e.g. '2019-08-01 00:00:00'.
  • Apply slightly different logic for casting JSON values with Postgres. Previously, Peewee just wrapped the value in the psycopg2 Json() helper. In this version, Peewee now dumps the json to a string and applies an explicit cast to the underlying JSON data-type (e.g. json or jsonb).

Bug fixes

  • Save hooks can now be called for models without a primary key.
  • Fixed bug in the conversion of Python values to JSON when using Postgres.
  • Fix for differentiating empty values from NULL values in model_to_dict.
  • Fixed a bug referencing primary-key values that required some kind of conversion (e.g., a UUID). See #1979 for details.
  • Add small jitter to the pool connection timestamp to avoid issues when multiple connections are checked-out at the same exact time.

View commits

3.9.6

03 Jun 14:57
Compare
Choose a tag to compare
  • Support nesting the Database instance as a context-manager. The outermost block will handle opening and closing the connection along with wrapping everything in a transaction. Nested blocks will use savepoints.
  • Add new session_start(), session_commit() and session_rollback() interfaces to the Database object to support using transactional controls in situations where a context-manager or decorator is awkward.
  • Fix error that would arise when attempting to do an empty bulk-insert.
  • Set isolation_level=None in SQLite connection constructor rather than afterwards using the setter.
  • Add create_table() method to Select query to implement CREATE TABLE AS.
  • Cleanup some declarations in the Sqlite C extension.
  • Add new example showing how to implement Reddit's ranking algorithm in SQL.

View commits

3.9.5

26 Apr 19:29
Compare
Choose a tag to compare
  • Added small helper for setting timezone when using Postgres.
  • Improved SQL generation for VALUES clause.
  • Support passing resolution to TimestampField as a power-of-10.
  • Small improvements to INSERT queries when the primary-key is not an auto-incrementing integer, but is generated by the database server (eg uuid).
  • Cleanups to virtual table implementation and python-to-sqlite value conversions.
  • Fixed bug related to binding previously-unbound models to a database using a context manager, #1913.

View commits

3.9.4

14 Apr 15:54
Compare
Choose a tag to compare
  • Add Model.bulk_update() method for bulk-updating fields across multiple model instances. Docs.
  • Add lazy_load parameter to ForeignKeyField. When initialized with lazy_load=False, the foreign-key will not use an additional query to resolve the related model instance. Instead, if the related model instance is not available, the underlying FK column value is returned (behaving like the "_id" descriptor).
  • Added Model.truncate_table() method.
  • The reflection and pwiz extensions now attempt to be smarter about converting database table and column names into snake-case. To disable this, you can set snake_case=False when calling the Introspector.introspect() method or use the -L (legacy naming) option with the pwiz script.
  • Bulk insert via insert_many() no longer require specification of the fields argument when the inserted rows are lists/tuples. In that case, the fields will be inferred to be all model fields except any auto-increment id.
  • Add DatabaseProxy, which implements several of the Database class context managers. This allows you to reference some of the special features of the database object without directly needing to initialize the proxy first.
  • Add support for window function frame exclusion and added built-in support for the GROUPS frame type.
  • Add support for chaining window functions by extending a previously-declared window function.
  • Playhouse Postgresql extension TSVectorField.match() method supports an additional argument plain, which can be used to control the parsing of the TS query.
  • Added very minimal JSONField to the playhouse MySQL extension.

View commits

3.9.3

23 Mar 03:20
Compare
Choose a tag to compare
  • Added cross-database support for NULLS FIRST/LAST when specifying the ordering for a query. Previously this was only supported for Postgres. Peewee will now generate an equivalent CASE statement for Sqlite and MySQL.
  • Added EXCLUDED helper for referring to the EXCLUDED namespace used with INSERT...ON CONFLICT queries, when referencing values in the conflicting row data.
  • Added helper method to the model Metadata class for setting the table name at run-time. Setting the Model._meta.table_name directly may have appeared to work in some situations, but could lead to subtle bugs. The new API is Model._meta.set_table_name().
  • Enhanced helpers for working with Peewee interactively, see doc.
  • Fix cache invalidation bug in DataSet that was originally reported on the sqlite-web project.
  • New example script implementing a hexastore.

View commits