Releases: coleifer/peewee
Releases · coleifer/peewee
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.
3.9.4
- Add
Model.bulk_update()
method for bulk-updating fields across multiple model instances. Docs. - Add
lazy_load
parameter toForeignKeyField
. When initialized withlazy_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
andpwiz
extensions now attempt to be smarter about converting database table and column names into snake-case. To disable this, you can setsnake_case=False
when calling theIntrospector.introspect()
method or use the-L
(legacy naming) option with thepwiz
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 theDatabase
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 argumentplain
, which can be used to control the parsing of the TS query. - Added very minimal
JSONField
to the playhouse MySQL extension.
3.9.3
- 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 equivalentCASE
statement for Sqlite and MySQL. - Added EXCLUDED helper for referring to the
EXCLUDED
namespace used withINSERT...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 theModel._meta.table_name
directly may have appeared to work in some situations, but could lead to subtle bugs. The new API isModel._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.