diff --git a/edbob/sqlalchemy.py b/edbob/sqlalchemy.py index 57f956b..39d4bf7 100644 --- a/edbob/sqlalchemy.py +++ b/edbob/sqlalchemy.py @@ -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()