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


Python op.bulk_insert方法代码示例

本文整理汇总了Python中alembic.op.bulk_insert方法的典型用法代码示例。如果您正苦于以下问题:Python op.bulk_insert方法的具体用法?Python op.bulk_insert怎么用?Python op.bulk_insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在alembic.op的用法示例。


在下文中一共展示了op.bulk_insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
    periodic_table = op.create_table(
        'opendaylight_periodic_task',
        sa.Column('state', sa.Enum(odl_const.PENDING, odl_const.PROCESSING,
                                   name='state'),
                  nullable=False),
        sa.Column('processing_operation', sa.String(70)),
        sa.Column('task', sa.String(70), primary_key=True),
        sa.Column('lock_updated', sa.TIMESTAMP, nullable=False,
                  server_default=sa.func.now(),
                  onupdate=sa.func.now())
    )
    op.bulk_insert(periodic_table,
                   [{'task': 'maintenance',
                     'state': odl_const.PENDING},
                    {'task': 'hostconfig',
                     'state': odl_const.PENDING}]) 
开发者ID:openstack,项目名称:networking-odl,代码行数:19,代码来源:6f7dfb241354_create_opendaylight_preiodic_task_table.py

示例2: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
    # Add collumn redirect_prefix
    op.add_column(
        u'l7policy',
        sa.Column(u'redirect_prefix', sa.String(255), nullable=True)
    )
    insert_table = sql.table(
        u'l7policy_action',
        sql.column(u'name', sa.String),
        sql.column(u'description', sa.String)
    )

    op.bulk_insert(
        insert_table,
        [
            {'name': 'REDIRECT_PREFIX'}
        ]
    ) 
开发者ID:openstack,项目名称:octavia,代码行数:20,代码来源:55874a4ceed6_add_l7policy_action_redirect_prefix.py

示例3: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():

    # create basic vars
    whiskies = Whisky.query.all()
    correlations = list()
    data = list()

    # loop twice to compare all whiskies
    for reference in whiskies:
        for whisky in whiskies:

            # add correlation if it does not already exists
            item = (whisky.id, reference.id)
            if item not in correlations and whisky.id != reference.id:
                data.append(reference.get_correlation(whisky))
                correlations.append(item)

    # bulk insert
    op.bulk_insert(Correlation.__table__, data) 
开发者ID:cuducos,项目名称:whiskyton,代码行数:21,代码来源:447b2802474f_seed_correlations.py

示例4: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
    conn = op.get_bind()

    temp_log_table = op.create_table(
        'temp_log',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('result_id', sa.Integer(), nullable=True),
        sa.Column('data', sa.LargeBinary(length=2048), nullable=True),
        sa.ForeignKeyConstraint(['result_id'], ['result.id'], ),
        sa.PrimaryKeyConstraint('id'))
    res = conn.execute('SELECT id, result_id, data FROM log')
    results = res.fetchall()
    if len(results) > 0:
        modified_logs = [{
            'id': r[0],
            'result_id': r[1],
            'data': msgpack.packb(json.loads(r[2]), use_bin_type=True)}
            for r in results]
        op.bulk_insert(temp_log_table, modified_logs)
    op.drop_table('log')
    op.rename_table('temp_log', 'log') 
开发者ID:chainer,项目名称:chainerui,代码行数:23,代码来源:e3db52a480f8_alter_log_data_type.py

示例5: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def downgrade():
    conn = op.get_bind()

    temp_log_table = op.create_table(
        'temp_log',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('result_id', sa.Integer(), nullable=True),
        sa.Column('data', sa.String(length=1024), nullable=True),
        sa.ForeignKeyConstraint(['result_id'], ['result.id'], ),
        sa.PrimaryKeyConstraint('id'))
    res = conn.execute('SELECT id, result_id, data FROM log')
    results = res.fetchall()
    if len(results) > 0:
        modified_logs = [{
            'id': r[0],
            'result_id': r[1],
            'data': json.dumps(msgpack.unpackb(r[2], raw=False))}
            for r in results]
        op.bulk_insert(temp_log_table, modified_logs)
    op.drop_table('log')
    op.rename_table('temp_log', 'log') 
开发者ID:chainer,项目名称:chainerui,代码行数:23,代码来源:e3db52a480f8_alter_log_data_type.py

示例6: test_bulk_insert_from_new_table

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def test_bulk_insert_from_new_table(self):
        context = op_fixture("postgresql", True)
        t1 = op.create_table(
            "ins_table",
            Column("id", Integer),
            Column("v1", String()),
            Column("v2", String()),
        )
        op.bulk_insert(
            t1,
            [
                {"id": 1, "v1": "row v1", "v2": "row v5"},
                {"id": 2, "v1": "row v2", "v2": "row v6"},
            ],
        )
        context.assert_(
            "CREATE TABLE ins_table (id INTEGER, v1 VARCHAR, v2 VARCHAR)",
            "INSERT INTO ins_table (id, v1, v2) VALUES "
            "(1, 'row v1', 'row v5')",
            "INSERT INTO ins_table (id, v1, v2) VALUES "
            "(2, 'row v2', 'row v6')",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:24,代码来源:test_bulk_insert.py

示例7: test_bulk_insert_inline_literal

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def test_bulk_insert_inline_literal(self):
        class MyType(TypeEngine):
            pass

        t1 = table("foo", column("id", Integer), column("data", MyType()))

        self.op.bulk_insert(
            t1,
            [
                {"id": 1, "data": self.op.inline_literal("d1")},
                {"id": 2, "data": self.op.inline_literal("d2")},
            ],
            multiinsert=False,
        )

        eq_(
            self.conn.execute(text("select id, data from foo")).fetchall(),
            [(1, "d1"), (2, "d2")],
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:21,代码来源:test_bulk_insert.py

示例8: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
    maint_table = op.create_table(
        'opendaylight_maintenance',
        sa.Column('id', sa.String(36), primary_key=True),
        sa.Column('state', sa.Enum(odl_const.PENDING, odl_const.PROCESSING,
                                   name='state'),
                  nullable=False),
        sa.Column('processing_operation', sa.String(70)),
        sa.Column('lock_updated', sa.TIMESTAMP, nullable=False,
                  server_default=sa.func.now(),
                  onupdate=sa.func.now())
    )

    # Insert the only row here that is used to synchronize the lock between
    # different Neutron processes.
    op.bulk_insert(maint_table,
                   [{'id': uuidutils.generate_uuid(),
                     'state': odl_const.PENDING}]) 
开发者ID:openstack,项目名称:networking-odl,代码行数:20,代码来源:703dbf02afde_add_journal_maintenance_table.py

示例9: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
    # all old rates are going in the bin
    conn = op.get_bind()
    conn.execute(text("UPDATE letter_rates SET end_date = :start WHERE end_date IS NULL"), start=CHANGEOVER_DATE)

    base_prices = {
        'second': 30,
        'first': 56,
    }
    op.bulk_insert(LetterRate.__table__, [
        {
            'id': uuid.uuid4(),
            'start_date': CHANGEOVER_DATE,
            'end_date': None,
            'sheet_count': sheet_count,
            'rate': (base_prices[post_class] + (5 * sheet_count)) / 100.0,
            'crown': crown,
            'post_class': post_class,
        }
        for sheet_count, crown, post_class in itertools.product(
            range(1, 6),
            [True, False],
            ['first', 'second']
        )
    ]) 
开发者ID:alphagov,项目名称:notifications-api,代码行数:27,代码来源:0306_letter_rates_price_rise.py

示例10: collect_existing_az_from_services_table

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def collect_existing_az_from_services_table(connection, services_table,
                                            az_table):
    az_name_to_id_mapping = dict()
    existing_az = []
    for service in connection.execute(services_table.select()):
        if service.availability_zone in az_name_to_id_mapping:
            continue

        az_id = uuidutils.generate_uuid()
        az_name_to_id_mapping[service.availability_zone] = az_id
        existing_az.append({
            'created_at': timeutils.utcnow(),
            'id': az_id,
            'name': service.availability_zone
        })

    op.bulk_insert(az_table, existing_az)

    return az_name_to_id_mapping 
开发者ID:openstack,项目名称:manila,代码行数:21,代码来源:1f0bd302c1a6_add_availability_zones_table.py

示例11: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    role_table = sa.table('role',
                          sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
                          sa.Column('name', sa.String(length=80), nullable=False),
                          sa.Column('description', sa.String(length=255), nullable=True),
                          sa.Column('parent_id', sa.Integer(), nullable=True),
                          )
    res = op.get_bind().execute('SELECT max(id)+1 FROM role')
    cm = 46
    for r in res.fetchall():
        cm = r[0]
    op.bulk_insert(role_table, [
        {'id': cm, 'name': 'import_store_data', 'description': u'导入店铺运营数据', 'parent_id': None},
    ], multiinsert=False)
    from sqlalchemy.sql import text
    op.get_bind().execute(text("ALTER SEQUENCE role_id_seq RESTART WITH " + str(cm + 1) + ";"))
    ### end Alembic commands ### 
开发者ID:betterlife,项目名称:betterlifepsi,代码行数:20,代码来源:16_a1ed2f75cb13_.py

示例12: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
    ### Caution: Only works in online mode!!!
    op.create_table('lecture_assistants',
            sa.Column('lecture', sa.Integer(), nullable=False),
            sa.Column('assistant', sa.Integer(), nullable=False),
            sa.ForeignKeyConstraint(['assistant'], ['users.id'], ),
            sa.ForeignKeyConstraint(['lecture'], ['lectures.id'], ),
            sa.PrimaryKeyConstraint('lecture', 'assistant')
    )
    lectures = sa.sql.table('lectures',
            sa.Column('id', sa.Integer),
            sa.Column('assistant', sa.Integer)
    )
    connection = op.get_bind()
    results = connection.execute(lectures.select())
    ins = []
    for res in results:
        if res.assistant!=None:
            ins.append({'lecture': res.id, 'assistant': res.assistant})
    lecture_assistants = sa.sql.table('lecture_assistants',
            sa.Column('lecture', sa.Integer(), nullable=False),
            sa.Column('assistant', sa.Integer(), nullable=False)
    )
    if ins:
        op.bulk_insert(lecture_assistants,ins) 
开发者ID:muesli-hd,项目名称:muesli,代码行数:27,代码来源:14d5e28d3626_lecture_assistants.py

示例13: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
    """
    Performs upgrade of database
    """

    comic = table('comic',
                  sa.Column('name', sa.Text),
                  sa.Column('type', sa.Text),
                  sa.Column('channelgid', sa.Text),
                  sa.Column('lastchecked', sa.Text),
                  sa.Column('url', sa.Text),
                  sa.Column('imgxpath', sa.Text),
                  sa.Column('txtxpath', sa.Text)
                  )
    op.bulk_insert(
        comic,
        [
            {'name': 'garfield', 'type': 'url', 'channelgid': '-1001105187138',
             'lastchecked': '1981/01/24',
             'url': 'https://s3.amazonaws.com/static.garfield.com/comics/garfield/#year#/#year#-#month#-#day#.gif',
             'imgxpath': 'False',
             'txtxpath': 'False'}
        ]
    ) 
开发者ID:iranzo,项目名称:stampython,代码行数:26,代码来源:a224268bda6b_feed_garfield_comic_data.py

示例14: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
    """
    Performs upgrade of database
    """

    comic = table('comic',
                  sa.Column('name', sa.Text),
                  sa.Column('type', sa.Text),
                  sa.Column('channelgid', sa.Text),
                  sa.Column('lastchecked', sa.Text),
                  sa.Column('url', sa.Text)
                  )
    op.bulk_insert(
        comic,
        [
            {'name': 'obichero', 'type': 'rss', 'channelgid': '-1001069507044',
             'lastchecked': '1981/01/24',
             'url': 'http://obichero.blogspot.com/feeds/posts/default'}
        ]
    ) 
开发者ID:iranzo,项目名称:stampython,代码行数:22,代码来源:6581184f2314_create_comic_entry_for_o_bichero.py

示例15: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
    """
    Performs upgrade of database
    """

    comic = table('comic',
                  sa.Column('name', sa.Text),
                  sa.Column('type', sa.Text),
                  sa.Column('channelgid', sa.Text),
                  sa.Column('lastchecked', sa.Text),
                  sa.Column('url', sa.Text)
                  )
    op.bulk_insert(
        comic,
        [
            {'name': 'mel', 'type': 'rss', 'channelgid': '-1001105187138',
             'lastchecked': '1981/01/24', 'url': 'http://elchistedemel.blogspot.com/feeds/posts/default'}
        ]
    ) 
开发者ID:iranzo,项目名称:stampython,代码行数:21,代码来源:03bbe0bc1832_create_comic_entry_for_mel.py


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