Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spoqa/sqlalchemy-utc
SQLAlchemy type to store aware datetime values
https://github.com/spoqa/sqlalchemy-utc
databases datetime orm python sqlalchemy timezone utc
Last synced: 10 days ago
JSON representation
SQLAlchemy type to store aware datetime values
- Host: GitHub
- URL: https://github.com/spoqa/sqlalchemy-utc
- Owner: spoqa
- License: mit
- Created: 2016-06-21T15:28:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-08-17T07:28:12.000Z (about 2 years ago)
- Last Synced: 2024-10-16T16:20:00.321Z (25 days ago)
- Topics: databases, datetime, orm, python, sqlalchemy, timezone, utc
- Language: Python
- Homepage: https://pypi.python.org/pypi/SQLAlchemy-Utc
- Size: 39.1 KB
- Stars: 101
- Watchers: 17
- Forks: 20
- Open Issues: 5
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE
Awesome Lists containing this project
README
SQLAlchemy-Utc
==============.. image:: https://badge.fury.io/py/SQLAlchemy-Utc.svg?
:target: https://pypi.python.org/pypi/SQLAlchemy-Utc
.. image:: https://travis-ci.com/spoqa/sqlalchemy-utc.svg?branch=master
:target: https://travis-ci.com/spoqa/sqlalchemy-utc
.. image:: https://codecov.io/github/spoqa/sqlalchemy-utc/coverage.svg?branch=master
:target: https://codecov.io/github/spoqa/sqlalchemy-utc?branch=masterThis package provides a drop-in replacement of SQLAlchemy's built-in `DateTime`_
type with ``timezone=True`` option enabled. Although SQLAlchemy's built-in
``DateTime`` type provides ``timezone=True`` option, since some vendors like
SQLite and MySQL don't provide ``timestamptz`` data type, the option doesn't
make any effect on these vendors.``UtcDateTime`` type is equivalent to the built-in ``DateTime`` with
``timezone=True`` option enabled on vendors that support ``timestamptz``
e.g. PostgreSQL, but on SQLite or MySQL, it shifts all ``datetime.datetime``
values to UTC offset before store them, and returns always aware
``datetime.datetime`` values through result sets.Long story short, ``UtcDateTime`` does:
- take only aware ``datetime.datetime``,
- return only aware ``datetime.datetime``,
- never take or return naive ``datetime.datetime``,
- ensure timestamps in database always to be encoded in UTC, and
- work as you'd expect.A SQLAlchemy helper function, ``utcnow()``, is provided as an alternative
to ``func.now()`` for generating ``UtcDateTime`` values on the server. For
example: ``Column('time', UtcDateTime(), default=utcnow())``.Written by `Hong Minhee`_ at Spoqa_, and distributed under MIT license.
.. _DateTime: http://docs.sqlalchemy.org/en/latest/core/type_basics.html#sqlalchemy.types.DateTime
.. _Hong Minhee: https://hongminhee.org/
.. _Spoqa: http://www.spoqa.com/