Releases: coleifer/peewee
Releases · coleifer/peewee
3.13.2
- Allow aggregate functions to support an
ORDER BY
clause, via the addition of anorder_by()
method to the function (fn
) instance. Refs #2094. - Fix
prefetch()
bug, where related "backref" instances were marked as dirty, even though they had no changes. Fixes #2091. - Support
LIMIT 0
. Previously a limit of 0 would be translated into effectively an unlimited query on MySQL. References #2084. - Support indexing into arrays using expressions with Postgres array fields. References #2085.
- Ensure postgres introspection methods return the columns for multi-column indexes in the correct order. Fixes #2104.
- Add support for arrays of UUIDs to postgres introspection.
- Fix introspection of columns w/capitalized table names in postgres (#2110).
- Fix to ensure correct exception is raised in SqliteQueueDatabase when iterating over cursor/result-set.
- Fix bug comparing subquery against a scalar value. Fixes #2118.
- Fix issue resolving composite primary-keys that include foreign-keys when building the model-graph. Fixes #2115.
- Allow model-classes to be passed as arguments, e.g., to a table function. Refs #2131.
- Ensure postgres
JSONField.concat()
accepts expressions as arguments.
3.13.1
Fix a regression when specifying keyword arguments to the atomic()
or
transaction()
helper methods. Note: this only occurs if you were using Sqlite
and were explicitly setting the lock_type=
parameter.
3.13.0
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()
andtransaction()
context-manager/decorator. - Fix non-deterministic join ordering issue when using the
filter()
API across several tables (#2063).
3.12.0
- Bulk insert (
insert_many()
andinsert_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 emptyreturning()
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 theto_buffer()
method. - Fixed APSW extension's
commit()
androllback()
methods to no-op if the database is in auto-commit mode. - Added
generate_always=
option to theIdentityField
(defaults to False).
3.11.2
- Implement
hash
interface forAlias
instances, allowing them to be used in multi-source queries.
3.11.1
- Fix bug in new
_pk
/get_id()
implementation for models that explicitly have disabled a primary-key.
3.11.0
- 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
andget_id()
interfaces so they no longer introduce the possibility of accidentally resolving the FK. - Allow
Field.contains()
,startswith()
andendswith()
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
andMySQLConnectorDatabase
did not respect theautoconnect
setting.
3.10.0
- Add a helper to
playhouse.mysql_ext
for creatingMatch
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 forDateField
andDateTimeField
that produces an expression returning a unix timestamp. - Add
autoconnect
parameter toDatabase
classes. This parameter defaults toTrue
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 specifyingautoconnect=False
, making an explicit call toDatabase.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()
andinsert()
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 MySQLdate_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.
3.9.6
- 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()
andsession_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 toSelect
query to implementCREATE TABLE AS
. - Cleanup some declarations in the Sqlite C extension.
- Add new example showing how to implement Reddit's ranking algorithm in SQL.
3.9.5
- 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.