Skip to content

Commit 1dadf0b

Browse files
committed
added docs for array column
1 parent 7600fd5 commit 1dadf0b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

docs/src/piccolo/schema/column_types.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,14 @@ a subset of the JSON data, and for filtering in a where clause.
204204
>>> Booking.data.arrow('name') == '"Alison"'
205205
>>> ).run_sync()
206206
[{'id': 1}]
207+
208+
-------------------------------------------------------------------------------
209+
210+
*****
211+
Array
212+
*****
213+
214+
Arrays of data can be stored, which can be useful when you want store lots of
215+
values without using foreign keys.
216+
217+
.. autoclass:: Array

piccolo/columns/column_types.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,25 @@ class Blob(Bytea):
13491349

13501350

13511351
class Array(Column):
1352+
"""
1353+
Used for storing lists of data.
1354+
1355+
**Example**
1356+
1357+
.. code-block:: python
1358+
1359+
class Ticket(Table):
1360+
seat_numbers = Array(base_column=Integer())
1361+
1362+
# Create
1363+
>>> Ticket(seat_numbers=[34, 35, 36]).save().run_sync()
1364+
1365+
# Query
1366+
>>> Ticket.select(Ticket.seat_numbers).run_sync()
1367+
{'seat_numbers': [34, 35, 36]}
1368+
1369+
"""
1370+
13521371
value_type = list
13531372

13541373
def __init__(
@@ -1357,6 +1376,9 @@ def __init__(
13571376
default: t.Union[t.List, t.Callable[[], t.List], None] = list,
13581377
**kwargs,
13591378
) -> None:
1379+
if isinstance(base_column, ForeignKey):
1380+
raise ValueError("Arrays of ForeignKeys aren't allowed.")
1381+
13601382
self._validate_default(default, (list, None))
13611383

13621384
self.base_column = base_column

0 commit comments

Comments
 (0)