Docs for ArrowType

This commit is contained in:
Konsta Vesterinen
2013-10-30 15:57:38 +02:00
parent eba82c16e0
commit c4a6616135

View File

@@ -14,6 +14,43 @@ from .scalar_coercible import ScalarCoercible
class ArrowType(types.TypeDecorator, ScalarCoercible): class ArrowType(types.TypeDecorator, ScalarCoercible):
"""
ArrowType provides way of saving Arrow_ objects into database. It
automatically changes Arrow_ objects to datatime objects on the way in and
datetime objects back to Arrow_ objects on the way out (when querying
database). ArrowType needs Arrow_ library installed.
.. _Arrow: http://crsmithdev.com/arrow/
::
from datetime import datetime
from sqlalchemy_utils import ArrowType
import arrow
class Article(Base):
__tablename__ = 'article'
id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.Unicode(255))
created_at = sa.Column(ArrowType)
article = Article(created_at=arrow.utcnow())
As you may expect all the arrow goodies come available:
::
article.created_at = article.created_at.replace(hours=-1)
article.created_at.humanize()
# 'an hour ago'
"""
impl = types.DateTime impl = types.DateTime
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):