本文整理汇总了Python中sqlalchemy.SmallInteger方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.SmallInteger方法的具体用法?Python sqlalchemy.SmallInteger怎么用?Python sqlalchemy.SmallInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.SmallInteger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def upgrade():
op.create_table("_portal_temp",
sa.Column("gid", sa.String(length=255), nullable=False),
sa.Column("receiver", sa.String(length=255), nullable=False, server_default=""),
sa.Column("conv_type", sa.SmallInteger(), nullable=False),
sa.Column("other_user_id", sa.String(length=255), nullable=True),
sa.Column("mxid", sa.String(length=255), nullable=True),
sa.Column("name", sa.String(), nullable=True),
sa.PrimaryKeyConstraint("gid", "receiver"),
sa.UniqueConstraint("mxid"))
c = op.get_bind()
c.execute("INSERT INTO _portal_temp (gid, receiver, conv_type, other_user_id, mxid, name) "
"SELECT portal.gid, (CASE WHEN portal.conv_type = 2 THEN portal.gid ELSE '' END), "
" portal.conv_type, portal.other_user_id, portal.mxid, portal.name "
"FROM portal")
c.execute("DROP TABLE portal")
c.execute("ALTER TABLE _portal_temp RENAME TO portal")
示例2: make_copy_ddl
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def make_copy_ddl(self, metadata: MetaData) -> DdlString:
copy_ddl_template = ".import {csv_file} {table_name}"
ddl = [".mode csv"]
for table_obj in metadata.tables.values():
table_name: str = table_obj.fullname
namespace = table_name[:table_name.index("_")]
model_name = table_name[table_name.index("_") + 1:]
csv_dir = self.data_path_prefix.joinpath(namespace)
csv_file = csv_dir.joinpath(model_name).with_suffix(".csv")
copy_ddl = copy_ddl_template.format(table_name=table_name, csv_file=csv_file)
ddl.append(copy_ddl)
ddl.append(f"UPDATE {table_name} SET")
set_statements = []
for col in table_obj.columns.values():
col_name = col.name
null_case = f"{col_name}=NULLIF({col_name}, '')"
set_statements.append(null_case)
if isinstance(col.type, SmallInteger):
bool_case = f"{col_name}=CASE {col_name} WHEN 'T' THEN 1 WHEN 'F' THEN 0 ELSE {col_name} END"
set_statements.append(bool_case)
set_statement = ",\n".join(set_statements) + ";"
ddl.append(set_statement)
return "\n".join(ddl)
示例3: test_change_deleted_column_type_to_boolean_with_fc
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def test_change_deleted_column_type_to_boolean_with_fc(self):
expected_types = {'mysql': mysql.TINYINT,
'ibm_db_sa': SmallInteger}
table_name_1 = 'abc'
table_name_2 = 'bcd'
table_1 = Table(table_name_1, self.meta,
Column('id', Integer, primary_key=True),
Column('deleted', Integer))
table_1.create()
table_2 = Table(table_name_2, self.meta,
Column('id', Integer, primary_key=True),
Column('foreign_id', Integer,
ForeignKey('%s.id' % table_name_1)),
Column('deleted', Integer))
table_2.create()
utils.change_deleted_column_type_to_boolean(self.engine, table_name_2)
table = utils.get_table(self.engine, table_name_2)
self.assertIsInstance(table.c.deleted.type,
expected_types.get(self.engine.name, Boolean))
示例4: operation_type_column
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def operation_type_column(self):
"""
Return the operation type column. By default the name of this column
is 'operation_type'.
"""
return sa.Column(
self.option('operation_type_column_name'),
sa.SmallInteger,
nullable=False,
index=True
)
示例5: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def upgrade():
op.add_column(
"projects", sa.Column("uploads_count", sa.SmallInteger(), nullable=True)
)
示例6: _create_post_table
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def _create_post_table(self):
"""
Creates the table to store the blog posts.
:return:
"""
with self._engine.begin() as conn:
post_table_name = self._table_name("post")
if not conn.dialect.has_table(conn, post_table_name):
self._post_table = sqla.Table(
post_table_name, self._metadata,
sqla.Column("id", sqla.Integer, primary_key=True),
sqla.Column("title", sqla.String(256)),
sqla.Column("text", sqla.Text),
sqla.Column("post_date", sqla.DateTime),
sqla.Column("last_modified_date", sqla.DateTime),
# if 1 then make it a draft
sqla.Column("draft", sqla.SmallInteger, default=0),
info=self._info
)
self._logger.debug("Created table with table name %s" %
post_table_name)
else:
self._post_table = self._metadata.tables[post_table_name]
self._logger.debug("Reflecting to table with table name %s" %
post_table_name)
示例7: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def upgrade():
op.drop_table("message")
op.create_table("message",
sa.Column("mxid", sa.String(length=255), nullable=True),
sa.Column("mx_room", sa.String(length=255), nullable=True),
sa.Column("gid", sa.String(length=255), nullable=False),
sa.Column("receiver", sa.String(length=255), nullable=False),
sa.Column("index", sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint("gid", "receiver", "index"),
sa.UniqueConstraint("mxid", "mx_room", name="_mx_id_room"))
示例8: downgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def downgrade():
op.create_table("_portal_temp",
sa.Column("gid", sa.String(length=255), nullable=False),
sa.Column("conv_type", sa.SmallInteger(), nullable=False),
sa.Column("other_user_id", sa.String(length=255), nullable=True),
sa.Column("mxid", sa.String(length=255), nullable=True),
sa.Column("name", sa.String(), nullable=True),
sa.PrimaryKeyConstraint("gid"),
sa.UniqueConstraint("mxid"))
c = op.get_bind()
c.execute("INSERT INTO _portal_temp (gid, conv_type, other_user_id, mxid, name) "
"SELECT portal.gid, portal.conv_type, portal.other_user_id, portal.mxid, portal.name "
"FROM portal")
c.execute("DROP TABLE portal")
c.execute("ALTER TABLE _portal_temp RENAME TO portal")
示例9: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def upgrade():
op.drop_table('message')
op.create_table('message',
sa.Column('mxid', sa.String(length=255), nullable=True),
sa.Column('mx_room', sa.String(length=255), nullable=True),
sa.Column('fbid', sa.String(length=127), nullable=False),
sa.Column('fb_receiver', sa.String(length=127), nullable=False),
sa.Column('index', sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint('fbid', 'fb_receiver', 'index'),
sa.UniqueConstraint('mxid', 'mx_room', name='_mx_id_room'))
示例10: downgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def downgrade():
op.drop_table('message')
op.create_table('message',
sa.Column('mxid', sa.String(length=255), nullable=True),
sa.Column('mx_room', sa.String(length=255), nullable=True),
sa.Column('fbid', sa.String(length=127), nullable=False),
sa.Column('index', sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint('fbid', 'index'),
sa.UniqueConstraint('mxid', 'mx_room', name='_mx_id_room'))
示例11: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def upgrade():
op.alter_column('property', 'order', type_=sa.SmallInteger)
# ### commands auto generated by Alembic - please adjust! ###
# ### end Alembic commands ###
开发者ID:openstate,项目名称:open-raadsinformatie,代码行数:6,代码来源:1afd444fda6b_change_property_order_column_to_.py
示例12: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def upgrade():
op.create_table(
'future_trade',
sa.Column('trade_id', sa.BigInteger, primary_key=True),
sa.Column('price', sa.Float, nullable=False),
sa.Column('amount', sa.Integer, nullable=False),
sa.Column('timestamp', sa.Integer, nullable=False),
sa.Column('trade_type', sa.SmallInteger, nullable=False),
sa.Column('contract_type', sa.SmallInteger, nullable=False),
)
op.create_index('future_trade_timestamp_index', 'future_trade', ['timestamp'])
示例13: metadata_transform
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def metadata_transform(metadata: MetaData) -> MetaData:
new_metadata = MetaData()
for table in metadata.tables.values():
# Need to namespace in the tablename because no schemas in sqlite
table_name = "{}_{}".format(metadata.schema, table.name)
# Remove dummy cols as no need for PKs (and we can't autoincrement anyway)
# and change booleans to int to stop checks from generating in the ddl
old_cols = [c for c in table.columns.values() if c.autoincrement is not True]
new_cols = []
for col in old_cols:
typ = col.type if not isinstance(col.type, Boolean) else SmallInteger
new_cols.append(Column(col.name, typ))
Table(table_name, new_metadata, *new_cols)
return new_metadata
示例14: test_change_deleted_column_type_to_boolean
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def test_change_deleted_column_type_to_boolean(self):
expected_types = {'mysql': mysql.TINYINT,
'ibm_db_sa': SmallInteger}
table_name = 'abc'
table = Table(table_name, self.meta,
Column('id', Integer, primary_key=True),
Column('deleted', Integer))
table.create()
utils.change_deleted_column_type_to_boolean(self.engine, table_name)
table = utils.get_table(self.engine, table_name)
self.assertIsInstance(table.c.deleted.type,
expected_types.get(self.engine.name, Boolean))
示例15: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import SmallInteger [as 别名]
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('rss_parser_feed_name_lut_version',
sa.Column('id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('feed_netloc', sa.Text(), autoincrement=False, nullable=True),
sa.Column('feed_name', sa.Text(), autoincrement=False, nullable=True),
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint('id', 'transaction_id')
)
op.create_index(op.f('ix_rss_parser_feed_name_lut_version_end_transaction_id'), 'rss_parser_feed_name_lut_version', ['end_transaction_id'], unique=False)
op.create_index(op.f('ix_rss_parser_feed_name_lut_version_feed_name'), 'rss_parser_feed_name_lut_version', ['feed_name'], unique=False)
op.create_index(op.f('ix_rss_parser_feed_name_lut_version_feed_netloc'), 'rss_parser_feed_name_lut_version', ['feed_netloc'], unique=False)
op.create_index(op.f('ix_rss_parser_feed_name_lut_version_id'), 'rss_parser_feed_name_lut_version', ['id'], unique=False)
op.create_index(op.f('ix_rss_parser_feed_name_lut_version_operation_type'), 'rss_parser_feed_name_lut_version', ['operation_type'], unique=False)
op.create_index(op.f('ix_rss_parser_feed_name_lut_version_transaction_id'), 'rss_parser_feed_name_lut_version', ['transaction_id'], unique=False)
op.create_table('rss_parser_funcs',
sa.Column('id', sa.BigInteger(), nullable=False),
sa.Column('version', sa.Integer(), nullable=True),
sa.Column('feed_name', sa.Text(), nullable=False),
sa.Column('enabled', sa.Boolean(), nullable=True),
sa.Column('func', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_rss_parser_funcs_feed_name'), 'rss_parser_funcs', ['feed_name'], unique=True)
op.create_index(op.f('ix_rss_parser_funcs_id'), 'rss_parser_funcs', ['id'], unique=False)
op.create_table('rss_parser_funcs_version',
sa.Column('id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('version', sa.Integer(), autoincrement=False, nullable=True),
sa.Column('feed_name', sa.Text(), autoincrement=False, nullable=True),
sa.Column('enabled', sa.Boolean(), autoincrement=False, nullable=True),
sa.Column('func', sa.Text(), autoincrement=False, nullable=True),
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint('id', 'transaction_id')
)
op.create_index(op.f('ix_rss_parser_funcs_version_end_transaction_id'), 'rss_parser_funcs_version', ['end_transaction_id'], unique=False)
op.create_index(op.f('ix_rss_parser_funcs_version_feed_name'), 'rss_parser_funcs_version', ['feed_name'], unique=False)
op.create_index(op.f('ix_rss_parser_funcs_version_id'), 'rss_parser_funcs_version', ['id'], unique=False)
op.create_index(op.f('ix_rss_parser_funcs_version_operation_type'), 'rss_parser_funcs_version', ['operation_type'], unique=False)
op.create_index(op.f('ix_rss_parser_funcs_version_transaction_id'), 'rss_parser_funcs_version', ['transaction_id'], unique=False)
op.create_table('rss_parser_feed_name_lut',
sa.Column('id', sa.BigInteger(), nullable=False),
sa.Column('feed_netloc', sa.Text(), nullable=False),
sa.Column('feed_name', sa.Text(), nullable=False),
sa.ForeignKeyConstraint(['feed_name'], ['rss_parser_funcs.feed_name'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('feed_netloc', 'feed_name')
)
op.create_index(op.f('ix_rss_parser_feed_name_lut_feed_name'), 'rss_parser_feed_name_lut', ['feed_name'], unique=False)
op.create_index(op.f('ix_rss_parser_feed_name_lut_feed_netloc'), 'rss_parser_feed_name_lut', ['feed_netloc'], unique=False)
op.create_index(op.f('ix_rss_parser_feed_name_lut_id'), 'rss_parser_feed_name_lut', ['id'], unique=False)
### end Alembic commands ###