add sqlalchemy.current_time()
This commit is contained in:
parent
03c51eb634
commit
ac530a50ab
1 changed files with 12 additions and 1 deletions
|
@ -31,9 +31,10 @@ from __future__ import absolute_import
|
||||||
from sqlalchemy import Table, Column, String
|
from sqlalchemy import Table, Column, String
|
||||||
|
|
||||||
from edbob.core import get_uuid
|
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):
|
def getset_factory(collection_class, proxy):
|
||||||
|
@ -72,3 +73,13 @@ def table_with_uuid(name, metadata, *args, **kwargs):
|
||||||
return Table(name, metadata,
|
return Table(name, metadata,
|
||||||
Column('uuid', String(32), primary_key=True, default=get_uuid),
|
Column('uuid', String(32), primary_key=True, default=get_uuid),
|
||||||
*args, **kwargs)
|
*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()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue