本文整理汇总了Python中sqlalchemy.dialects.mysql.DATETIME属性的典型用法代码示例。如果您正苦于以下问题:Python mysql.DATETIME属性的具体用法?Python mysql.DATETIME怎么用?Python mysql.DATETIME使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sqlalchemy.dialects.mysql
的用法示例。
在下文中一共展示了mysql.DATETIME属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: actual_complex_data
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def actual_complex_data(self, complex_table_schema):
res = {'id': 1}
for indx, complex_column_schema in enumerate(complex_table_schema):
if isinstance(complex_column_schema.sqla_obj, mysql.DATE):
data = complex_column_schema.data.strftime('%Y-%m-%d')
elif isinstance(complex_column_schema.sqla_obj, mysql.DATETIME):
data = complex_column_schema.data.strftime('%Y-%m-%d %H:%M:%S.%f')
elif isinstance(complex_column_schema.sqla_obj, mysql.TIMESTAMP):
data = complex_column_schema.data.strftime('%Y-%m-%d %H:%M:%S.%f')
elif isinstance(complex_column_schema.sqla_obj, mysql.TIME):
time = datetime.time(
complex_column_schema.data.seconds / 3600,
(complex_column_schema.data.seconds / 60) % 60,
complex_column_schema.data.seconds % 60,
complex_column_schema.data.microseconds
)
data = time.strftime('%H:%M:%S.%f')
else:
data = complex_column_schema.data
res.update({self._build_sql_column_name(indx): data})
return res
示例2: expected_complex_data
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def expected_complex_data(self, actual_complex_data, complex_table_schema):
expected_complex_data_dict = {'id': 1}
for indx, complex_column_schema in enumerate(complex_table_schema):
column_name = self._build_sql_column_name(indx)
if isinstance(complex_column_schema.sqla_obj, mysql.SET):
expected_complex_data_dict[column_name] = \
sorted(actual_complex_data[column_name])
elif isinstance(complex_column_schema.sqla_obj, mysql.DATETIME):
date_time_obj = \
complex_column_schema.data.isoformat()
expected_complex_data_dict[column_name] = date_time_obj
elif isinstance(complex_column_schema.sqla_obj, mysql.TIMESTAMP):
date_time_obj = \
complex_column_schema.data.replace(tzinfo=pytz.utc)
expected_complex_data_dict[column_name] = date_time_obj
elif isinstance(complex_column_schema.sqla_obj, mysql.TIME):
number_of_micros = transform_timedelta_to_number_of_microseconds(
complex_column_schema.data
)
expected_complex_data_dict[column_name] = number_of_micros
else:
expected_complex_data_dict[column_name] = \
complex_column_schema.data
return expected_complex_data_dict
示例3: load_dialect_impl
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def load_dialect_impl(self, dialect):
if dialect.name == 'mysql':
return dialect.type_descriptor(mysql.DATETIME(fsp=6))
return self.impl
示例4: upgrade
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def upgrade():
op.create_table('enforcements',
sa.Column('enforcement_id', mysql.INTEGER(unsigned=True), nullable=False, autoincrement=True),
sa.Column('account_id', mysql.INTEGER(unsigned=True)),
sa.Column('resource_id', sa.String(length=256), nullable=False),
sa.Column('action', sa.String(length=64), nullable=False),
sa.Column('timestamp', mysql.DATETIME(timezone=False), default=func.now()),
sa.Column('metrics', mysql.JSON()),
sa.PrimaryKeyConstraint('enforcement_id'))
示例5: upgrade
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('enqueued_tasks',
sa.Column('created_at', mysql.DATETIME(), nullable=False),
sa.Column('updated_at', mysql.DATETIME(), nullable=False),
sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
sa.Column('task_namespace', mysql.VARCHAR(length=100), nullable=True),
sa.Column('task_name', mysql.VARCHAR(length=255), nullable=True),
sa.PrimaryKeyConstraint('id'),
)
# ### end Alembic commands ###
示例6: upgrade
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('general_settings',
sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
sa.Column('name', mysql.VARCHAR(length=255), nullable=True),
sa.Column('value', sa.Text(), nullable=True),
sa.Column('created_at', mysql.DATETIME(), nullable=False),
sa.Column('updated_at', mysql.DATETIME(), nullable=False),
sa.PrimaryKeyConstraint('id'),
mysql_default_charset=u'utf8',
mysql_engine=u'InnoDB'
)
# ### end Alembic commands ###
示例7: upgrade
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('schedules',
sa.Column('created_at', mysql.DATETIME(), nullable=False),
sa.Column('updated_at', mysql.DATETIME(), nullable=False),
sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
sa.Column('cron', mysql.VARCHAR(length=255), nullable=True),
sa.Column('pipeline_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['pipeline_id'], [u'pipelines.id'], name=u'schedules_ibfk_1'),
sa.PrimaryKeyConstraint('id'),
mysql_default_charset=u'utf8',
mysql_engine=u'InnoDB'
)
# ### end Alembic commands ###
示例8: MillisecondDatetime
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def MillisecondDatetime():
"""Return a datetime type with millisecond precision.
Returns:
A column type.
"""
return sql.DateTime().with_variant(mysql.DATETIME(fsp=3), "mysql")
示例9: downgrade
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def downgrade():
op.add_column('spoolmessage', sa.Column(u'replyto_thread_id',
mysql.INTEGER(display_width=11),
nullable=True))
op.add_column('spoolmessage', sa.Column(u'draft_copied_from',
mysql.INTEGER(display_width=11),
nullable=True))
op.drop_column('spoolmessage', 'is_reply')
op.create_table(
u'draftthread',
sa.Column(u'created_at', mysql.DATETIME(), nullable=False),
sa.Column(u'updated_at', mysql.DATETIME(), nullable=False),
sa.Column(u'deleted_at', mysql.DATETIME(), nullable=True),
sa.Column(u'public_id', sa.BINARY(length=16), nullable=False),
sa.Column(u'id', mysql.INTEGER(display_width=11), nullable=False),
sa.Column(u'master_public_id', sa.BINARY(length=16), nullable=False),
sa.Column(u'thread_id', mysql.INTEGER(display_width=11),
autoincrement=False, nullable=False),
sa.Column(u'message_id', mysql.INTEGER(display_width=11),
autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['message_id'], [u'message.id'],
name=u'draftthread_ibfk_2'),
sa.ForeignKeyConstraint(['thread_id'], [u'thread.id'],
name=u'draftthread_ibfk_1'),
sa.PrimaryKeyConstraint(u'id'),
mysql_default_charset=u'utf8mb4',
mysql_engine=u'InnoDB'
)
示例10: upgrade
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def upgrade():
conn = op.get_bind()
conn.execute(text("ALTER TABLE accounttransaction "
" MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'"))
conn.execute(text("ALTER TABLE messagecategory"
" MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'"))
conn.execute(text("ALTER TABLE messagecontactassociation"
" MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'"))
conn.execute(text("ALTER TABLE transaction"
" MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'"))
conn.execute(text("ALTER TABLE accounttransaction DROP updated_at,"
"DROP deleted_at"))
conn.execute(text("ALTER TABLE messagecategory DROP updated_at,"
"DROP deleted_at"))
conn.execute(text("ALTER TABLE messagecontactassociation DROP updated_at,"
"DROP deleted_at"))
conn.execute(text("ALTER TABLE thread DROP deleted_at, DROP INDEX"
" ix_thread_namespace_id_recentdate_deleted_at"))
conn.execute(text("ALTER TABLE transaction DROP deleted_at,"
"DROP updated_at"))
if conn.engine.has_table('easdevice'):
# Run EAS specific migrations
conn.execute(text("ALTER TABLE easdevice"
" MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'"))
conn.execute(text("ALTER TABLE easdevice DROP deleted_at,"
"DROP updated_at"))
示例11: upgrade
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def upgrade():
op.add_column('message',
sa.Column('is_read', sa.Boolean(),
server_default=sa.sql.expression.false(),
nullable=False))
op.alter_column('usertagitem', 'created_at',
existing_type=mysql.DATETIME(), nullable=False)
op.alter_column('usertagitem', 'updated_at',
existing_type=mysql.DATETIME(), nullable=False)
from inbox.models.session import session_scope
from inbox.ignition import main_engine
engine = main_engine(pool_size=1, max_overflow=0)
Base = declarative_base()
Base.metadata.reflect(engine)
class Message(Base):
__table__ = Base.metadata.tables['message']
class ImapUid(Base):
__table__ = Base.metadata.tables['imapuid']
message = relationship('Message',
backref=backref('imapuids',
primaryjoin='and_('
'Message.id == ImapUid.message_id, '
'ImapUid.deleted_at == None)'),
primaryjoin='and_('
'ImapUid.message_id == Message.id,'
'Message.deleted_at == None)')
with session_scope(versioned=False) as db_session:
for uid in db_session.query(ImapUid).yield_per(500):
if uid.is_seen:
uid.message.is_read = True
db_session.commit()
示例12: downgrade
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def downgrade():
op.create_table('searchindexcursor',
sa.Column('created_at', mysql.DATETIME(), nullable=False),
sa.Column('updated_at', mysql.DATETIME(), nullable=False),
sa.Column('deleted_at', mysql.DATETIME(), nullable=True),
sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
sa.Column('transaction_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['transaction_id'], [u'transaction.id'], name=u'searchindexcursor_ibfk_1'),
sa.PrimaryKeyConstraint('id'),
mysql_default_charset=u'utf8mb4',
mysql_engine=u'InnoDB'
)
op.drop_table('contactsearchindexcursor')
示例13: upgrade
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def upgrade(): # noqa: D103
if context.config.get_main_option('sqlalchemy.url').startswith('mysql'):
op.alter_column(table_name='dag', column_name='last_scheduler_run',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='dag', column_name='last_pickled',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='dag', column_name='last_expired',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='dag_pickle', column_name='created_dttm',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='dag_run', column_name='execution_date',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='dag_run', column_name='start_date',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='dag_run', column_name='end_date',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='import_error', column_name='timestamp',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='job', column_name='start_date',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='job', column_name='end_date',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='job', column_name='latest_heartbeat',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='log', column_name='dttm',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='log', column_name='execution_date',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='sla_miss', column_name='execution_date',
type_=mysql.DATETIME(fsp=6),
nullable=False)
op.alter_column(table_name='sla_miss', column_name='timestamp',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='task_fail', column_name='execution_date',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='task_fail', column_name='start_date',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='task_fail', column_name='end_date',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='task_instance', column_name='execution_date',
type_=mysql.DATETIME(fsp=6),
nullable=False)
op.alter_column(table_name='task_instance', column_name='start_date',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='task_instance', column_name='end_date',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='task_instance', column_name='queued_dttm',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='xcom', column_name='timestamp',
type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='xcom', column_name='execution_date',
type_=mysql.DATETIME(fsp=6))
示例14: downgrade
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def downgrade(): # noqa: D103
if context.config.get_main_option('sqlalchemy.url').startswith('mysql'):
op.alter_column(table_name='dag', column_name='last_scheduler_run',
type_=mysql.DATETIME())
op.alter_column(table_name='dag', column_name='last_pickled',
type_=mysql.DATETIME())
op.alter_column(table_name='dag', column_name='last_expired',
type_=mysql.DATETIME())
op.alter_column(table_name='dag_pickle', column_name='created_dttm',
type_=mysql.DATETIME())
op.alter_column(table_name='dag_run', column_name='execution_date',
type_=mysql.DATETIME())
op.alter_column(table_name='dag_run', column_name='start_date',
type_=mysql.DATETIME())
op.alter_column(table_name='dag_run', column_name='end_date',
type_=mysql.DATETIME())
op.alter_column(table_name='import_error', column_name='timestamp',
type_=mysql.DATETIME())
op.alter_column(table_name='job', column_name='start_date',
type_=mysql.DATETIME())
op.alter_column(table_name='job', column_name='end_date',
type_=mysql.DATETIME())
op.alter_column(table_name='job', column_name='latest_heartbeat',
type_=mysql.DATETIME())
op.alter_column(table_name='log', column_name='dttm',
type_=mysql.DATETIME())
op.alter_column(table_name='log', column_name='execution_date',
type_=mysql.DATETIME())
op.alter_column(table_name='sla_miss', column_name='execution_date',
type_=mysql.DATETIME(), nullable=False)
op.alter_column(table_name='sla_miss', column_name='timestamp',
type_=mysql.DATETIME())
op.alter_column(table_name='task_fail', column_name='execution_date',
type_=mysql.DATETIME())
op.alter_column(table_name='task_fail', column_name='start_date',
type_=mysql.DATETIME())
op.alter_column(table_name='task_fail', column_name='end_date',
type_=mysql.DATETIME())
op.alter_column(table_name='task_instance', column_name='execution_date',
type_=mysql.DATETIME(),
nullable=False)
op.alter_column(table_name='task_instance', column_name='start_date',
type_=mysql.DATETIME())
op.alter_column(table_name='task_instance', column_name='end_date',
type_=mysql.DATETIME())
op.alter_column(table_name='task_instance', column_name='queued_dttm',
type_=mysql.DATETIME())
op.alter_column(table_name='xcom', column_name='timestamp',
type_=mysql.DATETIME())
op.alter_column(table_name='xcom', column_name='execution_date',
type_=mysql.DATETIME())
示例15: import_coin_info
# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import DATETIME [as 别名]
def import_coin_info(chain_param=None, ):
"""插入基础信息数据到 cmc_coin_v1_info"""
table_name = "cmc_coin_v1_info"
logging.info("更新 %s 开始", table_name)
has_table = engine_md.has_table(table_name)
# url = 'https://api.coinmarketcap.com/v2/listings/'
# dtype = {
# 'id': String(60),
# 'name': String(60),
# 'symbol': String(20),
# 'website_slug': String(60),
# }
url = 'https://api.coinmarketcap.com/v1/ticker/?limit=0'
dtype = {
'id': String(60),
'name': String(60),
'symbol': String(20),
'rank': Integer,
'price_usd': DOUBLE,
'price_btc': DOUBLE,
'24h_volume_usd': DOUBLE,
'market_cap_usd': DOUBLE,
'available_supply': DOUBLE,
'total_supply': DOUBLE,
'max_supply': DOUBLE,
'percent_change_1h': DOUBLE,
'percent_change_24h': DOUBLE,
'percent_change_7d': DOUBLE,
'last_updated': DATETIME,
}
rsp = requests.get(url)
if rsp.status_code != 200:
raise ValueError('请求 listings 相应失败')
json = rsp.json()
data_df = pd.DataFrame(json)
data_df['last_updated'] = data_df['last_updated'].apply(
lambda x: None if x is None else datetime.datetime.fromtimestamp(float(x)))
data_count = bunch_insert_on_duplicate_update(data_df, table_name, engine_md, dtype=dtype)
logging.info("更新 %s 完成 存量数据 %d 条", table_name, data_count)
if not has_table and engine_md.has_table(table_name):
alter_table_2_myisam(engine_md, [table_name])
# build_primary_key([table_name])
create_pk_str = """ALTER TABLE {table_name}
CHANGE COLUMN `id` `id` VARCHAR(60) NOT NULL FIRST ,
ADD PRIMARY KEY (`id`)""".format(table_name=table_name)
with with_db_session(engine_md) as session:
session.execute(create_pk_str)
# 更新 code_mapping 表
# update_from_info_table(table_name)