Releases: coleifer/peewee
3.16.2
3.16.1
- Add changes required for building against Cython 3.0 and set Cython language-level to 3.
- Ensure indexes aren't added to unindexed fields during introspection, #2691.
- Ensure we don't redundantly select same PK in prefetch when using PREFETCH_TYPE.JOIN.
- In Sqlite migrator, use Sqlite's builtin DROP and RENAME column facilities when possible. This can be overridden by passing
legacy=True
flag.
3.16.0
This release contains backwards-incompatible changes in the way Peewee
initializes connections to the underlying database driver. Previously, peewee
implemented autocommit semantics on-top of the existing DB-API transactional
workflow. Going forward, Peewee instead places the DB-API driver into
autocommit mode directly.
Why this change?
Previously, Peewee emulated autocommit behavior for top-level queries issued
outside of a transaction. This necessitated a number of checks which had to be
performed each time a query was executed, so as to ensure that we didn't end up
with uncommitted writes or, conversely, idle read transactions. By running the
underlying driver in autocommit mode, we can eliminate all these checks, since
we are already managing transactions ourselves.
Behaviorally, there should be no change -- Peewee will still treat top-level
queries outside of transactions as being autocommitted, while queries inside of
atomic()
/ with db:
blocks are implicitly committed at the end of the
block, or rolled-back if an exception occurs.
How might this affect me?
- If you are using the underlying database connection or cursors, e.g. via
Database.connection()
orDatabase.cursor()
, your queries will now be executed in autocommit mode. - The
commit=
argument is deprecated for thecursor()
,execute()
andexecute_sql()
methods. - If you have a custom
Database
implementation (whether for a database that is not officially supported, or for the purpose of overriding default behaviors), you will want to ensure that your connections are opened in autocommit mode.
Other changes:
- Some fixes to help with packaging in Python 3.11.
- MySQL
get_columns()
implementation now returns columns in their declared order.
3.15.4
- Raise an exception in
ReconnectMixin
if connection is lost while inside a transaction (if the transaction was interrupted presumably some changes were lost and explicit intervention is needed). - Add
db.Model
property to reduce boilerplate. - Add support for running
prefetch()
queries with joins instead of subqueries (this helps overcome a MySQL limitation about applying LIMITs to a subquery). - Add SQL
AVG
to whitelist to avoid coercing by default. - Allow arbitrary keywords in metaclass constructor, #2627
- Add a
pyproject.toml
to silence warnings from newer pips whenwheel
package is not available.
This release has a small helper for reducing boilerplate in some cases by
exposing a base model class as an attribute of the database instance.
# old:
db = SqliteDatabase('...')
class BaseModel(Model):
class Meta:
database = db
class MyModel(BaseModel):
pass
# new:
db = SqliteDatabase('...')
class MyModel(db.Model):
pass
3.15.3
- Add
scalars()
query method (complementsscalar()
), roughly equivalent to writing[t[0] for t in query.tuples()]
. - Small doc improvements
- Fix and remove some flaky test assertions with Sqlite INSERT + RETURNING.
- Fix innocuous failing Sqlite test on big-endian machines.
3.15.2
- Fix bug where field-specific conversions were being applied to the pattern used for LIKE / ILIKE operations. Refs #2609
- Fix possible infinite loop when accidentally invoking the
__iter__
method on certainColumn
subclasses. Refs #2606 - Add new helper for specifying which Model a particular selected column-like should be bound to, in queries with joins that select from multiple sources.
3.15.1
- Fix issue introduced in Sqlite 3.39.0 regarding the propagation of column subtypes in subqueries. Affected sqlite changelog extension when used with JSON columns.
- Fix bug where cockroachdb server version was not set when beginning a transaction on an unopened database.
3.15.0
Rollback behavior change in commit ab43376 (GH #2026). Peewee will no longer
automatically return the cursor rowcount
for certain bulk-inserts. This
should only affect users of MySQL and Sqlite who relied on a bulk INSERT
returning the rowcount
(as opposed to the cursor's lastrowid
). The
rowcount
behavior is still available chaining the as_rowcount()
method:
# NOTE: this change only affects MySQL or Sqlite.
db = MySQLDatabase(...)
# Previously, bulk inserts of the following forms would return the rowcount.
query = User.insert_many(...) # Bulk insert.
query = User.insert_from(...) # Bulk insert (INSERT INTO .. SELECT FROM).
# Previous behavior (peewee 3.12 - 3.14.10):
# rows_inserted = query.execute()
# New behavior:
last_id = query.execute()
# To get the old behavior back:
rows_inserted = query.as_rowcount().execute()
This release contains a fix for a long-standing request to allow data-modifying
queries to support CTEs. CTEs are now supported for use with INSERT, DELETE and
UPDATE queries - see #2152.
Additionally, this release adds better support for using the new RETURNING
syntax with Sqlite automatically. Specify returning_clause=True
when
initializing your SqliteDatabase
and all bulk inserts will automatically
specify a RETURNING
clause, returning the newly-inserted primary keys. This
functionality requires Sqlite 3.35 or newer.
Smaller changes:
- Add
shortcuts.insert_where()
helper for generating conditional INSERT with a bit less boilerplate. - Fix bug in
test_utils.count_queres()
which could erroneously include pool events such as connect/disconnect, etc.
3.14.10
- Add shortcut for conditional insert using sub-select, see #2528
- Add convenience
left_outer_join()
method to query. - Add
selected_columns
property to Select queries. - Add
name
property to Alias instances. - Fix regression in tests introduced by change to DataSet in 3.14.9.
3.14.9
- Allow calling
table_exists()
with a model-class, refs - Improve
is_connection_usable()
method ofMySQLDatabase
class. - Better support for VIEWs with
playhouse.dataset.DataSet
and sqlite-web. - Support INSERT / ON CONFLICT in
playhosue.kv
for newer Sqlite. - Add
ArrayField.contained_by()
method, a corollary tocontains()
and thecontains_any()
methods. - Support cyclical foreign-key relationships in reflection/introspection, and also for sqlite-web.
- Add magic methods for FTS5 field to optimize, rebuild and integrity check the full-text index.
- Add fallbacks in
setup.py
in the event distutils is not available.