当前位置: 首页>>代码示例>>Python>>正文


Python sqlalchemy.Unicode方法代码示例

本文整理汇总了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) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:24,代码来源:3ae3c668f444_.py

示例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) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:26,代码来源:a7e91b18a460_.py

示例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) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:26,代码来源:3c6e9dd7fbac_.py

示例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) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:22,代码来源:205bda834127_.py

示例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) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:27,代码来源:4023571658f8_.py

示例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)) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:26,代码来源:dceb6cd3c41e_.py

示例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) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:24,代码来源:2ac117d0a6f5_.py

示例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) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:23,代码来源:3429d523e51f_.py

示例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) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:22,代码来源:449903fb6e35_.py

示例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')
    ) 
开发者ID:Net-ng,项目名称:kansha,代码行数:20,代码来源:5791b368ac26_new_background_positions.py

示例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') 
开发者ID:openspending,项目名称:spendb,代码行数:19,代码来源:test_dataset.py

示例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 
开发者ID:SFDO-Tooling,项目名称:CumulusCI,代码行数:24,代码来源:utils.py

示例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 
开发者ID:SFDO-Tooling,项目名称:CumulusCI,代码行数:27,代码来源:test_utils.py

示例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) 
开发者ID:SFDO-Tooling,项目名称:CumulusCI,代码行数:18,代码来源:test_utils.py


注:本文中的sqlalchemy.Unicode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。