Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SQLAlchemy type to store aware datetime values

License

NotificationsYou must be signed in to change notification settings

spoqa/sqlalchemy-utc

Repository files navigation

https://badge.fury.io/py/SQLAlchemy-Utc.svg?https://travis-ci.com/spoqa/sqlalchemy-utc.svg?branch=masterhttps://codecov.io/github/spoqa/sqlalchemy-utc/coverage.svg?branch=master

This package provides a drop-in replacement of SQLAlchemy's built-inDateTimetype withtimezone=True option enabled. Although SQLAlchemy's built-inDateTime type providestimezone=True option, since some vendors likeSQLite and MySQL don't providetimestamptz data type, the option doesn'tmake any effect on these vendors.

UtcDateTime type is equivalent to the built-inDateTime withtimezone=True option enabled on vendors that supporttimestamptze.g. PostgreSQL, but on SQLite or MySQL, it shifts alldatetime.datetimevalues to UTC offset before store them, and returns always awaredatetime.datetime values through result sets.

Long story short,UtcDateTime does:

  • take only awaredatetime.datetime,
  • return only awaredatetime.datetime,
  • never take or return naivedatetime.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 alternativetofunc.now() for generatingUtcDateTime values on the server. Forexample:Column('time', UtcDateTime(), default=utcnow()).

Written byHong Minhee atSpoqa, and distributed under MIT license.

Packages

No packages published

Contributors11

Languages


[8]ページ先頭

©2009-2025 Movatter.jp