本文整理汇总了Python中sqlalchemy.Binary方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.Binary方法的具体用法?Python sqlalchemy.Binary怎么用?Python sqlalchemy.Binary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.Binary方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _cast
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Binary [as 别名]
def _cast(t, expr):
arg, typ = expr.op().args
sa_arg = t.translate(arg)
sa_type = t.get_sqla_type(typ)
# specialize going from an integer type to a timestamp
if isinstance(arg.type(), dt.Integer) and isinstance(sa_type, sa.DateTime):
return sa.func.timezone('UTC', sa.func.to_timestamp(sa_arg))
if arg.type().equals(dt.binary) and typ.equals(dt.string):
return sa.func.encode(sa_arg, 'escape')
if typ.equals(dt.binary):
# decode yields a column of memoryview which is annoying to deal with
# in pandas. CAST(expr AS BYTEA) is correct and returns byte strings.
return sa.cast(sa_arg, sa.Binary())
return sa.cast(sa_arg, sa_type)
示例2: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Binary [as 别名]
def upgrade():
op.create_table(
'storage_data',
sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True),
sqlalchemy.Column('created', sqlalchemy.DateTime),
sqlalchemy.Column('namespace', sqlalchemy.String),
sqlalchemy.Column('key', sqlalchemy.String, nullable=False),
sqlalchemy.Column('value', sqlalchemy.Binary)
)
db_manager.Session.remove()
db_manager.Session.configure(bind=op.get_bind())
session = db_manager.Session()
db_manager.set_meta_data('schema_version', 7, session=session)
session.commit()
示例3: sa_binary
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Binary [as 别名]
def sa_binary(_, satype, nullable=True):
return dt.Binary(nullable=nullable)
示例4: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Binary [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('email', sa.String(), nullable=False),
sa.Column('_password', sa.Binary(), nullable=False),
sa.Column('authenticated', sa.Boolean(), nullable=True),
sa.Column('email_confirmation_sent_on', sa.DateTime(), nullable=True),
sa.Column('email_confirmed', sa.Boolean(), nullable=True),
sa.Column('email_confirmed_on', sa.DateTime(), nullable=True),
sa.Column('registered_on', sa.DateTime(), nullable=True),
sa.Column('last_logged_in', sa.DateTime(), nullable=True),
sa.Column('current_logged_in', sa.DateTime(), nullable=True),
sa.Column('role', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
op.create_table('items',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('notes', sa.String(), nullable=True),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
示例5: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Binary [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('users', sa.Column('registration_ip', sa.Binary(), nullable=True))
# ### end Alembic commands ###
示例6: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Binary [as 别名]
def upgrade():
op.create_table('bans',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_time', sa.DateTime(), nullable=True),
sa.Column('admin_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('user_ip', sa.Binary(length=16), nullable=True),
sa.Column('reason', sa.String(length=2048), nullable=False),
sa.ForeignKeyConstraint(['admin_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id'),
)
op.create_index('user_ip_16', 'bans', ['user_ip'], unique=True, mysql_length=16)
op.create_index('user_ip_4', 'bans', ['user_ip'], unique=True, mysql_length=4)
示例7: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Binary [as 别名]
def upgrade():
for prefix in TABLE_PREFIXES:
op.add_column(prefix + '_torrents', sa.Column('uploader_ip', sa.Binary(), nullable=True))
# ### end Alembic commands ###
示例8: create_md_model
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Binary [as 别名]
def create_md_model(metadata=None):
return Table('metric_dimension', metadata,
Column('dimension_set_id', Binary),
Column('name', String(255)),
Column('value', String(255)))
示例9: create_mde_model
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Binary [as 别名]
def create_mde_model(metadata=None):
return Table('metric_definition', metadata,
Column('id', Binary),
Column('name', String(255)),
Column('tenant_id', String(255)),
Column('region', String(255)))
示例10: create_mdd_model
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Binary [as 别名]
def create_mdd_model(metadata=None):
return Table('metric_definition_dimensions', metadata,
Column('id', Binary),
Column('metric_definition_id', Binary),
Column('metric_dimension_set_id', Binary))
示例11: create_am_model
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Binary [as 别名]
def create_am_model(metadata=None):
return Table('alarm_metric', metadata,
Column('alarm_id', String(36)),
Column('metric_definition_dimensions_id', Binary))
示例12: BinaryArray
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Binary [as 别名]
def BinaryArray(length: int):
"""Return a fixed size binary array column type.
Args:
length: The length of the column.
Returns:
A column type.
"""
return sql.Binary(length).with_variant(mysql.BINARY(length), "mysql")