Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/src/piccolo/api_reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,43 @@ UUID
.. autoclass:: UUID4
:members:


TimestampCustom
~~~~~~~~~~~~~~~

.. autoclass:: TimestampCustom
:members:

TimestampOffset
~~~~~~~~~~~~~~~

.. autoclass:: TimestampOffset
:members:

TimestampNow
~~~~~~~~~~~~

.. autoclass:: TimestampNow
:members:

TimestamptzCustom
~~~~~~~~~~~~~~~~~

.. autoclass:: TimestamptzCustom
:members:

TimestamptzOffset
~~~~~~~~~~~~~~~~~

.. autoclass:: TimestamptzOffset
:members:

TimestamptzNow
~~~~~~~~~~~~~~

.. autoclass:: TimestamptzNow
:members:

-------------------------------------------------------------------------------

Testing
Expand Down
9 changes: 8 additions & 1 deletion piccolo/columns/column_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,8 @@ def __set__(self, obj, value: Union[int, None]):

class Timestamp(Column):
"""
Used for storing datetimes. Uses the ``datetime`` type for values.
Used for storing timezone naive datetimes. Uses the ``datetime`` type for
values.

**Example**

Expand All @@ -905,6 +906,12 @@ class Concert(Table):
>>> await Concert.select(Concert.starts)
{'starts': datetime.datetime(2050, 1, 1, 0, 0)}

.. note::
We recommend using
:class:`Timestamptz <piccolo.columns.column_types.Timestamptz>`
columns if possible - having timezone information makes the timestamp
unambiguous.

"""

value_type = datetime
Expand Down
2 changes: 2 additions & 0 deletions piccolo/columns/defaults/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .base import * # noqa
from .date import * # noqa
from .interval import * # noqa
from .time import * # noqa
from .timestamp import * # noqa
from .timestamptz import * # noqa
from .uuid import * # noqa
5 changes: 5 additions & 0 deletions piccolo/columns/defaults/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def python(self):


class TimestampNow(Default):
"""
The current timestamp, in the local time of the machine that Python is
running on.
"""

@property
def postgres(self):
return "current_timestamp"
Expand Down
4 changes: 4 additions & 0 deletions piccolo/columns/defaults/timestamptz.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def python(self):


class TimestamptzNow(TimestampNow):
"""
The current timestamp in UTC.
"""

@property
def cockroach(self):
return "current_timestamp"
Expand Down