From ac530a50ab5500345ebf0c34d3c60dd6d9ec8409 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 11 Jul 2012 00:42:31 -0500 Subject: [PATCH] add sqlalchemy.current_time() --- edbob/sqlalchemy.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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()