本文整理汇总了Python中sqlalchemy.func.current_timestamp方法的典型用法代码示例。如果您正苦于以下问题:Python func.current_timestamp方法的具体用法?Python func.current_timestamp怎么用?Python func.current_timestamp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.func
的用法示例。
在下文中一共展示了func.current_timestamp方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_with_timezone
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def test_with_timezone(self, connection):
# get a date with a tzinfo
somedate = testing.db.connect().scalar(
func.current_timestamp().select()
)
assert somedate.tzinfo
connection.execute(tztable.insert(), id=1, name="row1", date=somedate)
row = connection.execute(
select([tztable.c.date], tztable.c.id == 1)
).first()
eq_(row[0], somedate)
eq_(
somedate.tzinfo.utcoffset(somedate),
row[0].tzinfo.utcoffset(row[0]),
)
result = connection.execute(
tztable.update(tztable.c.id == 1).returning(tztable.c.date),
name="newname",
)
row = result.first()
assert row[0] >= somedate
示例2: define_tables
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def define_tables(cls, metadata):
t2 = Table("t2", metadata, Column("nextid", Integer))
Table(
"t1",
metadata,
Column(
"id",
Integer,
primary_key=True,
default=sa.select([func.max(t2.c.nextid)]).scalar_subquery(),
),
Column("data", String(30)),
)
Table(
"date_table",
metadata,
Column(
"date_id",
DateTime,
default=text("current_timestamp"),
primary_key=True,
),
)
示例3: _datetime_server_default_fixture
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def _datetime_server_default_fixture(self):
return func.current_timestamp()
示例4: test_compare_current_timestamp_fn_w_binds
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def test_compare_current_timestamp_fn_w_binds(self):
self._compare_default_roundtrip(
DateTime(), func.timezone("utc", func.current_timestamp())
)
示例5: get_previsions
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def get_previsions(cls, session, end_date=None):
"""Retrieve future validated requests per user."""
# Searching for requests with an timeframe
# [NOW()] ---------- ([end_date])?
# exemples:
# <f --r1---- t>
# <f --r2-- t>
# <f ------r3-------- t>
# <f ----------- r4 -------------------- t>
# => Matching period are periods ending after NOW()
# and if an end_date is specified periods starting before it:
if end_date:
future_requests = session.query(
cls.user_id, func.sum(cls.days)).\
filter(cls.date_to >= func.current_timestamp(),
cls.date_from < end_date,
cls.vacation_type_id == 1,
cls.status == 'APPROVED_ADMIN').\
group_by(cls.user_id).\
order_by(cls.user_id)
else:
future_requests = session.query(
cls.user_id, func.sum(cls.days)).\
filter(cls.date_to >= func.current_timestamp(),
cls.vacation_type_id == 1,
cls.status == 'APPROVED_ADMIN').\
group_by(cls.user_id).\
order_by(cls.user_id)
ret = {}
for user_id, total in future_requests:
ret[user_id] = total
return ret
示例6: test_no_paren_fns
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def test_no_paren_fns(self):
for fn, expected in [
(func.uid(), "uid"),
(func.UID(), "UID"),
(func.sysdate(), "sysdate"),
(func.row_number(), "row_number()"),
(func.rank(), "rank()"),
(func.now(), "CURRENT_TIMESTAMP"),
(func.current_timestamp(), "CURRENT_TIMESTAMP"),
(func.user(), "USER"),
]:
self.assert_compile(fn, expected)
示例7: setup_class
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def setup_class(cls):
global tztable, notztable, metadata
metadata = MetaData(testing.db)
# current_timestamp() in postgresql is assumed to return
# TIMESTAMP WITH TIMEZONE
tztable = Table(
"tztable",
metadata,
Column("id", Integer, primary_key=True),
Column(
"date",
DateTime(timezone=True),
onupdate=func.current_timestamp(),
),
Column("name", String(20)),
)
notztable = Table(
"notztable",
metadata,
Column("id", Integer, primary_key=True),
Column(
"date",
DateTime(timezone=False),
onupdate=cast(
func.current_timestamp(), DateTime(timezone=False)
),
),
Column("name", String(20)),
)
metadata.create_all()
示例8: tstzs
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def tstzs(self):
if self._tstzs is None:
with testing.db.begin() as conn:
lower = conn.scalar(func.current_timestamp().select())
upper = lower + datetime.timedelta(1)
self._tstzs = (lower, upper)
return self._tstzs
示例9: test_three
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def test_three(self):
self.tables.t
actual_ts = self.bind.scalar(
func.current_timestamp()
) - datetime.timedelta(days=5)
self._test(
func.current_timestamp() - datetime.timedelta(days=5),
{
"hour": actual_ts.hour,
"year": actual_ts.year,
"month": actual_ts.month,
},
)
示例10: test_eleven
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def test_eleven(self):
self._test(
func.current_timestamp() - func.current_timestamp(),
{"year": 0, "month": 0, "day": 0, "hour": 0},
)
示例11: test_twelve
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def test_twelve(self):
t = self.tables.t
actual_ts = self.bind.scalar(func.current_timestamp()).replace(
tzinfo=None
) - datetime.datetime(2012, 5, 10, 12, 15, 25)
self._test(
func.current_timestamp()
- func.coalesce(t.c.dtme, func.current_timestamp()),
{"day": actual_ts.days},
)
示例12: test_compile
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def test_compile(self):
for dialect in all_dialects(exclude=("sybase",)):
bindtemplate = BIND_TEMPLATES[dialect.paramstyle]
self.assert_compile(
func.current_timestamp(), "CURRENT_TIMESTAMP", dialect=dialect
)
self.assert_compile(func.localtime(), "LOCALTIME", dialect=dialect)
if dialect.name in ("firebird",):
self.assert_compile(
func.nosuchfunction(), "nosuchfunction", dialect=dialect
)
else:
self.assert_compile(
func.nosuchfunction(), "nosuchfunction()", dialect=dialect
)
# test generic function compile
class fake_func(GenericFunction):
__return_type__ = sqltypes.Integer
def __init__(self, arg, **kwargs):
GenericFunction.__init__(self, arg, **kwargs)
self.assert_compile(
fake_func("foo"),
"fake_func(%s)"
% bindtemplate
% {"name": "fake_func_1", "position": 1},
dialect=dialect,
)
functions._registry["_default"].pop("fake_func")
示例13: test_ansi_functions_with_args
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import current_timestamp [as 别名]
def test_ansi_functions_with_args(self):
ct = func.current_timestamp("somearg")
self.assert_compile(ct, "CURRENT_TIMESTAMP(:current_timestamp_1)")