本文整理汇总了Python中sqlalchemy.TIMESTAMP属性的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.TIMESTAMP属性的具体用法?Python sqlalchemy.TIMESTAMP怎么用?Python sqlalchemy.TIMESTAMP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.TIMESTAMP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def upgrade():
periodic_table = op.create_table(
'opendaylight_periodic_task',
sa.Column('state', sa.Enum(odl_const.PENDING, odl_const.PROCESSING,
name='state'),
nullable=False),
sa.Column('processing_operation', sa.String(70)),
sa.Column('task', sa.String(70), primary_key=True),
sa.Column('lock_updated', sa.TIMESTAMP, nullable=False,
server_default=sa.func.now(),
onupdate=sa.func.now())
)
op.bulk_insert(periodic_table,
[{'task': 'maintenance',
'state': odl_const.PENDING},
{'task': 'hostconfig',
'state': odl_const.PENDING}])
开发者ID:openstack,项目名称:networking-odl,代码行数:19,代码来源:6f7dfb241354_create_opendaylight_preiodic_task_table.py
示例2: test_mysql_timestamp
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def test_mysql_timestamp(metadata):
Table("simple", metadata, Column("id", INTEGER, primary_key=True), Column("timestamp", mysql.TIMESTAMP))
assert (
generate_code(metadata)
== """\
# coding: utf-8
from sqlalchemy import Column, Integer, TIMESTAMP
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
metadata = Base.metadata
class Simple(Base):
__tablename__ = 'simple'
id = Column(Integer, primary_key=True)
timestamp = Column(TIMESTAMP)
"""
)
示例3: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def upgrade():
op.create_table(
'opendaylightjournal',
sa.Column('id', sa.String(36), primary_key=True),
sa.Column('object_type', sa.String(36), nullable=False),
sa.Column('object_uuid', sa.String(36), nullable=False),
sa.Column('operation', sa.String(36), nullable=False),
sa.Column('data', sa.PickleType, nullable=True),
sa.Column('state',
sa.Enum('pending', 'processing', 'failed', 'completed',
name='state'),
nullable=False, default='pending'),
sa.Column('retry_count', sa.Integer, default=0),
sa.Column('created_at', sa.DateTime, default=sa.func.now()),
sa.Column('last_retried', sa.TIMESTAMP, server_default=sa.func.now(),
onupdate=sa.func.now())
)
开发者ID:openstack,项目名称:networking-odl,代码行数:19,代码来源:37e242787ae5_opendaylight_neutron_mechanism_driver_.py
示例4: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def upgrade():
maint_table = op.create_table(
'opendaylight_maintenance',
sa.Column('id', sa.String(36), primary_key=True),
sa.Column('state', sa.Enum(odl_const.PENDING, odl_const.PROCESSING,
name='state'),
nullable=False),
sa.Column('processing_operation', sa.String(70)),
sa.Column('lock_updated', sa.TIMESTAMP, nullable=False,
server_default=sa.func.now(),
onupdate=sa.func.now())
)
# Insert the only row here that is used to synchronize the lock between
# different Neutron processes.
op.bulk_insert(maint_table,
[{'id': uuidutils.generate_uuid(),
'state': odl_const.PENDING}])
示例5: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def upgrade():
op.create_table(
'opendaylightjournal_new',
sa.Column('seqnum', sa.BigInteger(),
primary_key=True, autoincrement=True),
sa.Column('object_type', sa.String(36), nullable=False),
sa.Column('object_uuid', sa.String(36), nullable=False),
sa.Column('operation', sa.String(36), nullable=False),
sa.Column('data', sa.PickleType, nullable=True),
sa.Column('state',
sa.Enum('pending', 'processing', 'failed', 'completed',
name='state'),
nullable=False, default='pending'),
sa.Column('retry_count', sa.Integer, default=0),
sa.Column('created_at', sa.DateTime, default=sa.func.now()),
sa.Column('last_retried', sa.TIMESTAMP, server_default=sa.func.now(),
onupdate=sa.func.now()),
)
示例6: test_reflect_select
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def test_reflect_select(table, table_using_test_dataset):
for table in [table, table_using_test_dataset]:
assert len(table.c) == 18
assert isinstance(table.c.integer, Column)
assert isinstance(table.c.integer.type, types.Integer)
assert isinstance(table.c.timestamp.type, types.TIMESTAMP)
assert isinstance(table.c.string.type, types.String)
assert isinstance(table.c.float.type, types.Float)
assert isinstance(table.c.boolean.type, types.Boolean)
assert isinstance(table.c.date.type, types.DATE)
assert isinstance(table.c.datetime.type, types.DATETIME)
assert isinstance(table.c.time.type, types.TIME)
assert isinstance(table.c.bytes.type, types.BINARY)
assert isinstance(table.c['record.age'].type, types.Integer)
assert isinstance(table.c['record.name'].type, types.String)
assert isinstance(table.c['nested_record.record.age'].type, types.Integer)
assert isinstance(table.c['nested_record.record.name'].type, types.String)
assert isinstance(table.c.array.type, types.ARRAY)
rows = table.select().execute().fetchall()
assert len(rows) == 1000
示例7: setUp
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def setUp(self):
self.sa_meta = sa.MetaData()
self.data = [
[17.124, 1.12, 3.14, 13.37],
[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4],
[True, None, False, True],
['string 1', 'string 2', None, 'string 3'],
[datetime(2007, 7, 13, 1, 23, 34, 123456),
None,
datetime(2006, 1, 13, 12, 34, 56, 432539),
datetime(2010, 8, 13, 5, 46, 57, 437699), ],
["Test Text", "Some#More#Test# Text", "!@#$%%^&*&", None],
]
self.table = sa.Table(
'unit_test_table',
self.sa_meta,
sa.Column('real_col', sa.REAL),
sa.Column('bigint_col', sa.BIGINT),
sa.Column('int_col', sa.INTEGER),
sa.Column('smallint_col', sa.SMALLINT),
sa.Column('bool_col', sa.BOOLEAN),
sa.Column('str_col', sa.VARCHAR),
sa.Column('timestamp_col', sa.TIMESTAMP),
sa.Column('plaintext_col', sa.TEXT),
)
self.expected_datatypes = [
pa.float32(),
pa.int64(),
pa.int32(),
pa.int16(),
pa.bool_(),
pa.string(),
pa.timestamp('ns'),
pa.string(),
]
示例8: mysql_timestamp
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def mysql_timestamp(): # noqa: D103
return mysql.TIMESTAMP(fsp=6)
示例9: sa_timestamp
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def sa_timestamp(): # noqa: D103
return sa.TIMESTAMP(timezone=True)
示例10: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def upgrade():
"""Apply Add RenderedTaskInstanceFields table"""
json_type = sa.JSON
conn = op.get_bind() # pylint: disable=no-member
if conn.dialect.name != "postgresql":
# Mysql 5.7+/MariaDB 10.2.3 has JSON support. Rather than checking for
# versions, check for the function existing.
try:
conn.execute("SELECT JSON_VALID(1)").fetchone()
except (sa.exc.OperationalError, sa.exc.ProgrammingError):
json_type = sa.Text
op.create_table(
TABLE_NAME, # pylint: disable=no-member
sa.Column('dag_id', sa.String(length=250), nullable=False),
sa.Column('task_id', sa.String(length=250), nullable=False),
sa.Column('execution_date', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('rendered_fields', json_type(), nullable=False),
sa.PrimaryKeyConstraint('dag_id', 'task_id', 'execution_date')
)
示例11: test_alter_column_modify_datetime_default
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def test_alter_column_modify_datetime_default(self):
# use CHANGE format when the datatype is DATETIME or TIMESTAMP,
# as this is needed for a functional default which is what you'd
# get with a DATETIME/TIMESTAMP. Will also work in the very unlikely
# case the default is a fixed timestamp value.
context = op_fixture("mysql")
op.alter_column(
"t",
"c",
existing_type=DATETIME(),
server_default=text("CURRENT_TIMESTAMP"),
)
context.assert_(
"ALTER TABLE t CHANGE c c DATETIME NULL DEFAULT CURRENT_TIMESTAMP"
)
示例12: test_add_timestamp_server_default_current_timestamp
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def test_add_timestamp_server_default_current_timestamp(self):
self._run_alter_col(
{"type": TIMESTAMP()},
{"server_default": text("CURRENT_TIMESTAMP")},
)
示例13: test_add_timestamp_server_default_now
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def test_add_timestamp_server_default_now(self):
self._run_alter_col(
{"type": TIMESTAMP()},
{"server_default": text("NOW()")},
compare={"server_default": text("CURRENT_TIMESTAMP")},
)
示例14: test_add_timestamp_server_default_current_timestamp_bundle_onupdate
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def test_add_timestamp_server_default_current_timestamp_bundle_onupdate(
self,
):
# note SQLAlchemy reflection bundles the ON UPDATE part into the
# server default reflection see
# https://github.com/sqlalchemy/sqlalchemy/issues/4652
self._run_alter_col(
{"type": TIMESTAMP()},
{
"server_default": text(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
)
},
)
示例15: test_compare_timestamp_current_timestamp_diff
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import TIMESTAMP [as 别名]
def test_compare_timestamp_current_timestamp_diff(self):
self._compare_default_roundtrip(TIMESTAMP(), None, "CURRENT_TIMESTAMP")