add sqlalchemy.current_time()

This commit is contained in:
Lance Edgar 2012-07-11 00:42:31 -05:00
parent 03c51eb634
commit ac530a50ab

View file

@ -31,9 +31,10 @@ from __future__ import absolute_import
from sqlalchemy import Table, Column, String
from edbob.core import get_uuid
from edbob.time import utc_time
__all__ = ['getset_factory', 'table_with_uuid']
__all__ = ['getset_factory', 'table_with_uuid', 'current_time']
def getset_factory(collection_class, proxy):
@ -72,3 +73,13 @@ def table_with_uuid(name, metadata, *args, **kwargs):
return Table(name, metadata,
Column('uuid', String(32), primary_key=True, default=get_uuid),
*args, **kwargs)
def current_time(context):
"""
This function may be provided to the ``default`` parameter of a
:class:`sqlalchemy.Column` class definition. Doing so will ensure the
column's default value will be the current time in UTC.
"""
return utc_time()