本文整理汇总了Python中sqlalchemy.Unicode方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.Unicode方法的具体用法?Python sqlalchemy.Unicode怎么用?Python sqlalchemy.Unicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.Unicode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def upgrade():
userstatus.create(op.get_bind())
op.add_column(
'users',
sa.Column('status', sa.Enum(*userstatus_choices, name='userstatus'), nullable=True)
)
op.add_column('users', sa.Column('status_info', sa.Unicode(), nullable=True))
# Set user's status field.
conn = op.get_bind()
query = textwrap.dedent(
"UPDATE users SET status = 'active', status_info = 'migrated' WHERE is_active = 't';"
)
conn.execute(query)
query = textwrap.dedent(
"UPDATE users SET status = 'inactive', status_info = 'migrated' WHERE is_active <> 't';"
)
conn.execute(query)
op.alter_column('users', column_name='status', nullable=False)
op.drop_column('users', 'is_active')
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:23,代码来源:0d553d59f369_users_replace_is_active_to_status_and_its_info.py
示例2: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def upgrade():
try:
op.create_table('eventhandlercondition',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('eventhandler_id', sa.Integer(), nullable=True),
sa.Column('Key', sa.Unicode(length=255), nullable=False),
sa.Column('Value', sa.Unicode(length=2000), nullable=True),
sa.Column('comparator', sa.Unicode(length=255), nullable=True),
sa.ForeignKeyConstraint(['eventhandler_id'], ['eventhandler.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('eventhandler_id', 'Key', name='ehcix_1')
)
except (OperationalError, ProgrammingError, InternalError) as exx:
if "duplicate column name" in str(exx.orig).lower():
print("Good. Table eventhandlercondition already exists.")
else:
print("Table already exists")
print(exx)
except Exception as exx:
print("Could not add Table eventhandlercondition")
print (exx)
示例3: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def upgrade():
try:
op.add_column('policy', sa.Column('adminuser', sa.Unicode(length=256), nullable=True))
except Exception as exx:
print('Adding of column "adminuser" in table policy failed: {!r}'.format(exx))
print('This is expected behavior if this column already exists.')
# Now that we added the column in the table, we can move the "user" from admin-policies to
# the "adminuser" column
try:
bind = op.get_bind()
session = orm.Session(bind=bind)
pol_name = None
for policy in session.query(Policy).filter(Policy.user != "", Policy.scope == "admin"):
pol_name = policy.name
# move the "user" to the "adminuser"
policy.adminuser = policy.user
policy.user = u""
session.commit()
except Exception as exx:
session.rollback()
print("Failed to migrate column adminuser in policies due to error in policy '{0!s}'.".format(pol_name))
print(exx)
示例4: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def upgrade():
try:
op.create_table('clientapplication',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('ip', sa.Unicode(length=255), nullable=False),
sa.Column('hostname', sa.Unicode(length=255), nullable=True),
sa.Column('clienttype', sa.Unicode(length=255), nullable=False),
sa.Column('lastseen', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('ip', 'clienttype', name='caix')
)
op.create_index(op.f('ix_clientapplication_clienttype'), 'clientapplication', ['clienttype'], unique=False)
op.create_index(op.f('ix_clientapplication_id'), 'clientapplication', ['id'], unique=False)
op.create_index(op.f('ix_clientapplication_ip'), 'clientapplication', ['ip'], unique=False)
except (OperationalError, ProgrammingError, InternalError) as exx:
if "duplicate column name" in str(exx.orig).lower():
print("Good. Table clientapplication already exists.")
else:
print("Table already exists")
print(exx)
except Exception as exx:
print("Could not add Table clientapplication")
print (exx)
示例5: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def upgrade():
try:
op.create_table('authcache',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('first_auth', sa.DateTime(), nullable=True),
sa.Column('last_auth', sa.DateTime(), nullable=True),
sa.Column('username', sa.Unicode(length=64), nullable=True),
sa.Column('resolver', sa.Unicode(length=120), nullable=True),
sa.Column('realm', sa.Unicode(length=120), nullable=True),
sa.Column('client_ip', sa.Unicode(length=40), nullable=True),
sa.Column('user_agent', sa.Unicode(length=120), nullable=True),
sa.Column('authentication', sa.Unicode(length=64), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_authcache_realm'), 'authcache', ['realm'], unique=False)
op.create_index(op.f('ix_authcache_resolver'), 'authcache', ['resolver'], unique=False)
op.create_index(op.f('ix_authcache_username'), 'authcache', ['username'], unique=False)
except Exception as exx:
print ("Could not add table 'authcache' - probably already exists!")
print (exx)
示例6: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def upgrade():
try:
op.create_table('passwordreset',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('recoverycode', sa.Unicode(length=255), nullable=False),
sa.Column('username', sa.Unicode(length=64), nullable=False),
sa.Column('realm', sa.Unicode(length=64), nullable=False),
sa.Column('resolver', sa.Unicode(length=64), nullable=True),
sa.Column('email', sa.Unicode(length=255), nullable=True),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.Column('expiration', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_passwordreset_realm'), 'passwordreset',
['realm'], unique=False)
op.create_index(op.f('ix_passwordreset_username'), 'passwordreset',
['username'], unique=False)
except (OperationalError, ProgrammingError, InternalError) as exx:
if "duplicate column name" in str(exx.orig).lower():
print("Good. Table passwordreset already exists.")
else:
print(exx)
except Exception as exx:
print ("Could not add table 'passwordreset'")
print (exx)
示例7: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def upgrade():
try:
try:
create_seq(Sequence('policycondition_seq'))
except Exception as _e:
pass
op.create_table('policycondition',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('policy_id', sa.Integer(), nullable=False),
sa.Column('section', sa.Unicode(length=255), nullable=False),
sa.Column('Key', sa.Unicode(length=255), nullable=False),
sa.Column('comparator', sa.Unicode(length=255), nullable=False),
sa.Column('Value', sa.Unicode(length=2000), nullable=False),
sa.Column('active', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['policy_id'], ['policy.id'], ),
sa.PrimaryKeyConstraint('id'),
mysql_row_format='DYNAMIC'
)
except Exception as exx:
print("Could not create table policycondition: {!r}".format(exx))
try:
op.drop_column('policy', 'condition')
except Exception as exx:
print("Could not drop column policy.condition: {!r}".format(exx))
示例8: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def upgrade():
try:
op.create_table('smtpserver',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('identifier', sa.Unicode(length=255), nullable=False),
sa.Column('server', sa.Unicode(length=255), nullable=False),
sa.Column('port', sa.Integer(), nullable=True),
sa.Column('username', sa.Unicode(length=255), nullable=True),
sa.Column('password', sa.Unicode(length=255), nullable=True),
sa.Column('sender', sa.Unicode(length=255), nullable=True),
sa.Column('tls', sa.Boolean(), nullable=True),
sa.Column('description', sa.Unicode(length=2000), nullable=True),
sa.PrimaryKeyConstraint('id')
)
except (OperationalError, ProgrammingError, InternalError) as exx:
if "duplicate column name" in str(exx.orig).lower():
print("Good. Column smtpserver already exists.")
else:
print(exx)
except Exception as exx:
print ("Could not add table 'smtpserver'")
print (exx)
示例9: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def upgrade():
try:
op.alter_column('subscription', 'level', type_=sa.Unicode(80),
existing_type=sa.Unicode(30))
except Exception as exx:
print("Could not make field 'level' longer.")
print (exx)
try:
op.alter_column('subscription', 'application', type_=sa.Unicode(80),
existing_type=sa.Unicode(30))
except Exception as exx:
print("Could not make field 'application' longer.")
print (exx)
try:
op.alter_column('subscription', 'for_name', type_=sa.Unicode(80),
existing_type=sa.Unicode(30))
except Exception as exx:
print("Could not make field 'for_name' longer.")
print (exx)
示例10: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def upgrade():
try:
op.create_table('radiusserver',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('identifier', sa.Unicode(length=255), nullable=False),
sa.Column('server', sa.Unicode(length=255), nullable=False),
sa.Column('port', sa.Integer(), nullable=True),
sa.Column('secret', sa.Unicode(length=255), nullable=True),
sa.Column('description', sa.Unicode(length=2000), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('identifier')
)
except (OperationalError, ProgrammingError, InternalError) as exx:
if "duplicate column name" in str(exx.orig).lower():
print("Good. Table 'radiusserver' already exists.")
else:
print(exx)
except Exception as exx:
print ("Could not add table 'radiusserver'")
print (exx)
示例11: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def upgrade():
op.alter_column('board', 'background_position', nullable=True, server_default=None)
board = sa.Table(
'board',
sa.MetaData(),
sa.Column('background_position', sa.Unicode),
)
bind = op.get_bind()
bind.execute(
board.update().where(
board.c.background_position == u'repeat'
).values(background_position=u'tile')
)
bind.execute(
board.update().where(
board.c.background_position == u'cover'
).values(background_position=u'fill')
)
示例12: test_generate_db_entry_table
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def test_generate_db_entry_table(self):
assert self.ds.fact_table.table.name == 'test__facts', \
self.ds.fact_table.table.name
cols = self.ds.fact_table.table.c
assert '_id' in cols, cols
assert isinstance(cols['_id'].type, Unicode)
assert 'year' in cols, cols
assert isinstance(cols['year'].type, Integer)
assert 'amount' in cols
assert isinstance(cols['amount'].type, Integer)
assert 'field' in cols
assert isinstance(cols['field'].type, Unicode)
assert 'to_label' in cols, cols
assert isinstance(cols['to_label'].type, Unicode)
assert 'func_label' in cols
assert isinstance(cols['func_label'].type, Unicode)
assert_raises(KeyError, cols.__getitem__, 'foo')
示例13: create_table
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def create_table(mapping, metadata):
"""Given a mapping data structure (from mapping.yml) and SQLAlchemy
metadata, create a table matching the mapping.
Mapping should be a dict-like with keys "fields", "table" and
optionally "oid_as_pk" and "record_type" """
fields = []
_handle_primary_key(mapping, fields)
# make a field list to create
for field in fields_for_mapping(mapping):
if mapping["oid_as_pk"] and field["sf"] == "Id":
continue
fields.append(Column(field["db"], Unicode(255)))
if "record_type" in mapping:
fields.append(Column("record_type", Unicode(255)))
t = Table(mapping["table"], metadata, *fields)
if t.exists():
raise BulkDataException(f"Table already exists: {mapping['table']}")
return t
示例14: test_sql_bulk_insert_from_records__sqlite
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def test_sql_bulk_insert_from_records__sqlite(self):
engine, metadata = create_db_memory()
fields = [
Column("id", Integer(), primary_key=True, autoincrement=True),
Column("sf_id", Unicode(24)),
]
id_t = Table("TestTable", metadata, *fields)
id_t.create()
model = type("TestModel", (object,), {})
mapper(model, id_t)
util = bulkdata.utils.SqlAlchemyMixin()
util.metadata = metadata
session = create_session(bind=engine, autocommit=False)
util.session = session
connection = session.connection()
util._sql_bulk_insert_from_records(
connection=connection,
table="TestTable",
columns=("id", "sf_id"),
record_iterable=([f"{x}", f"00100000000000{x}"] for x in range(10)),
)
assert session.query(model).count() == 10
示例15: test_create_table_legacy_oid_mapping
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Unicode [as 别名]
def test_create_table_legacy_oid_mapping(self):
mapping_file = os.path.join(os.path.dirname(__file__), "mapping_v1.yml")
content = parse_from_yaml(mapping_file)
account_mapping = content["Insert Contacts"]
with temporary_dir() as d:
tmp_db_path = os.path.join(d, "temp.db")
engine, metadata = create_db_file(tmp_db_path)
t = create_table(account_mapping, metadata)
assert t.name == "contacts"
assert isinstance(t.columns["sf_id"].type, Unicode)
assert isinstance(t.columns["first_name"].type, Unicode)
assert isinstance(t.columns["last_name"].type, Unicode)
assert isinstance(t.columns["email"].type, Unicode)