Changes in 3.0¶
This document describes changes to be aware of when switching from 2.x to 3.x.
I tried to keep changes backwards-compatible as much as possible. In some
places, APIs that have changed will trigger a
get_conn()has changed to
execution_context()is replaced by simply using the database instance as a context-manager.
- For a connection context without a transaction, use
Database.drop_tables(), as well as
Model.drop_table()all default to
safe=True(create if not exists, drop if exists).
connect_kwargsattribute has been renamed to
Model Meta options¶
db_tablehas changed to
db_table_funchas changed to
order_byhas been removed (used for specifying a default ordering to be applied to SELECT queries).
validate_backrefshas been removed. Back-references are no longer validated.
- Accessing raw model data is now done using
db_columnhas changed to
db_fieldclass attribute changed to
field_type(used if you are implementing custom field subclasses)
model_classattribute has changed to
PrimaryKeyFieldhas been renamed to
ForeignKeyFieldconstructor has the following changes: *
rel_modelhas changed to
to_fieldhas changed to
related_namehas changed to
ManyToManyFieldis now included in the main
- Removed the extension fields
The C extension that contained implementations of the query result wrappers has been removed.
Select.aggregate_rows() has been removed. This helper
was used to de-duplicate left-join queries to give the appearance of efficiency
when iterating a model and it’s relations. In practice, the complexity of the
code and it’s somewhat limited usefulness convinced me to scrap it. You can
prefetch() to achieve the same result.
_selecthas changed to
case() helper has moved from the
into the main peewee module.
cast() method is no longer a function, but instead is
a method on all column-like objects.
The following extensions are no longer included in the
The SQLite extension module’s
VirtualModel class accepts slightly
arguments- used to specify arbitrary arguments appended after any columns being defined on the virtual table. Should be a list of strings.
extension_options) - arbitrary options for the virtual table that appear after columns and
prefix_arguments- a list of strings that should appear before any arguments or columns in the virtual table declaration.
So, when declaring a model for a virtual table, it will be constructed roughly like this:
CREATE VIRTUAL TABLE "table name" USING extension_module ( prefix arguments, field definitions, arguments, options)
The query-builder has been rewritten from the ground-up to be more flexible and powerful. There is now a generic, lower-level API for constructing queries.
The virtual-table implementation from sqlite-vtfunc has been folded into the peewee codebase.
- Murmurhash implementation has been corrected.
- Couple small quirks in the BM25 ranking code have been addressed.
- Numerous user-defined functions for hashing and ranking are now included.
- Support for update, commit and rollback hooks.
- Support for SQLite online backup API.
LSMTableimplementation to support the lsm1 extension.