Skip to content

Commit 99339ee

Browse files
authored
Merge branch 'piccolo-orm:master' into disable_migrations
2 parents 111e2d6 + a9defac commit 99339ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+894
-245
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ jobs:
142142
strategy:
143143
matrix:
144144
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
145-
cockroachdb-version: ["v24.1.0"]
145+
cockroachdb-version: ["v25.4.3"]
146146
steps:
147147
- uses: actions/checkout@v3
148148
- name: Set up Python ${{ matrix.python-version }}

CHANGES.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
Changes
22
=======
33

4+
1.32.0
5+
------
6+
7+
Added the ``having`` clause, which is useful when working with ``group_by``.
8+
9+
For example, here we get the number of albums per band, but exclude any bands
10+
with less than 2 albums:
11+
12+
.. code-block:: python
13+
14+
>>> from piccolo.query.functions.aggregate import Count
15+
16+
>>> await Album.select(
17+
... Album.band.name.as_alias('band_name'),
18+
... Count()
19+
... ).group_by(
20+
... Album.band
21+
... ).having(
22+
... Count() >= 2
23+
... )
24+
25+
[
26+
{"band_name": "Pythonistas", "count": 2},
27+
]
28+
29+
We also updated our CockroachDB support to the latest version (thanks to
30+
@sinisaos for this).
31+
32+
-------------------------------------------------------------------------------
33+
434
1.31.0
535
------
636

docs/src/piccolo/api_reference/index.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,32 @@ UUID
111111
~~~~
112112

113113
.. autoclass:: UUID4
114+
115+
.. autoclass:: UUID7
116+
117+
118+
Timestamp
119+
~~~~~~~~~
120+
121+
.. autoclass:: TimestampCustom
122+
:members:
123+
124+
.. autoclass:: TimestampOffset
125+
:members:
126+
127+
.. autoclass:: TimestampNow
128+
:members:
129+
130+
Timestamptz
131+
~~~~~~~~~~~
132+
133+
.. autoclass:: TimestamptzCustom
134+
:members:
135+
136+
.. autoclass:: TimestamptzOffset
137+
:members:
138+
139+
.. autoclass:: TimestamptzNow
114140
:members:
115141

116142
-------------------------------------------------------------------------------
@@ -144,3 +170,15 @@ QueryString
144170
.. currentmodule:: piccolo.querystring
145171

146172
.. autoclass:: QueryString
173+
174+
-------------------------------------------------------------------------------
175+
176+
Custom Types
177+
------------
178+
179+
BasicTypes
180+
~~~~~~~~~~
181+
182+
.. currentmodule:: piccolo.custom_types
183+
184+
.. autoclass:: BasicTypes

docs/src/piccolo/contributing/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Make sure the test database exists:
2222
.. code-block:: console
2323
2424
cockroach sql --insecure
25-
>>> create database piccolo
26-
>>> use piccolo
25+
>>> create database piccolo;
26+
>>> use piccolo;
2727
2828
-------------------------------------------------------------------------------
2929

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Conditional functions
2+
=====================
3+
4+
.. currentmodule:: piccolo.query.functions.conditional
5+
6+
Coalesce
7+
--------
8+
9+
.. autoclass:: Coalesce

docs/src/piccolo/functions/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Functions can be used to modify how queries are run, and what is returned.
1313
./basic_usage
1414
./aggregate
1515
./array
16+
./conditional
1617
./datetime
1718
./math
1819
./string
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. _having:
2+
3+
having
4+
======
5+
6+
You can use the ``having`` clause with the following queries:
7+
8+
* :ref:`Select`
9+
10+
It is used in combination with the :ref:`group_by` clause, to filter the
11+
grouped rows.
12+
13+
The syntax is identical to the :ref:`where` clause.
14+
15+
-------------------------------------------------------------------------------
16+
17+
Example
18+
-------
19+
20+
In the following example, we get the number of albums per band (filtering out
21+
any bands with less than 2 albums).
22+
23+
.. hint:: You can run this query in the :ref:`playground`.
24+
25+
.. code-block:: python
26+
27+
>>> from piccolo.query.functions.aggregate import Count
28+
29+
>>> await Album.select(
30+
... Album.band.name.as_alias('band_name'),
31+
... Count()
32+
... ).group_by(
33+
... Album.band
34+
... ).having(
35+
... Count() >= 2
36+
... )
37+
38+
[
39+
{"band_name": "Pythonistas", "count": 2},
40+
]

docs/src/piccolo/query_clauses/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ by modifying the return values.
2525
./distinct
2626
./freeze
2727
./group_by
28+
./having
2829
./lock_rows
2930
./offset
3031
./on_conflict

piccolo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__VERSION__ = "1.31.0"
1+
__VERSION__ = "1.32.0"

piccolo/apps/migrations/auto/migration_manager.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from piccolo.columns import Column, column_types
1919
from piccolo.columns.column_types import ForeignKey, Serial
2020
from piccolo.engine import engine_finder
21+
from piccolo.engine.cockroach import CockroachTransaction
2122
from piccolo.query import Query
2223
from piccolo.query.base import DDL
2324
from piccolo.query.constraints import get_fk_constraint_name
@@ -984,7 +985,11 @@ async def run(self, backwards: bool = False):
984985
engine.transaction()
985986
if self.wrap_in_transaction
986987
else SkippedTransaction()
987-
):
988+
) as transaction:
989+
if isinstance(transaction, CockroachTransaction):
990+
# To enable DDL rollbacks in CockroachDB.
991+
await transaction.autocommit_before_ddl(enabled=False)
992+
988993
if not self.preview:
989994
if direction == "backwards":
990995
raw_list = self.raw_backwards

0 commit comments

Comments
 (0)