當前位置: 首頁>>代碼示例>>Python>>正文


Python postgresql.JSONB屬性代碼示例

本文整理匯總了Python中sqlalchemy.dialects.postgresql.JSONB屬性的典型用法代碼示例。如果您正苦於以下問題:Python postgresql.JSONB屬性的具體用法?Python postgresql.JSONB怎麽用?Python postgresql.JSONB使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在sqlalchemy.dialects.postgresql的用法示例。


在下文中一共展示了postgresql.JSONB屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: upgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def upgrade():
    op.create_table(
        'error_logs',
        IDColumn(),
        sa.Column('created_at', sa.DateTime(timezone=True),
                  server_default=sa.func.now(), index=True),
        sa.Column('severity', sa.Enum('critical', 'error', 'warning', 'info', 'debug', name='errorlog_severity'),
                  index=True),
        sa.Column('source', sa.String),
        sa.Column('user', GUID, sa.ForeignKey('users.uuid'), nullable=True, index=True),
        sa.Column('is_read', sa.Boolean, default=False, index=True),
        sa.Column('is_cleared', sa.Boolean, default=False, index=True),
        sa.Column('message', sa.Text),
        sa.Column('context_lang', sa.String),
        sa.Column('context_env', postgresql.JSONB()),
        sa.Column('request_url', sa.String, nullable=True),
        sa.Column('request_status', sa.Integer, nullable=True),
        sa.Column('traceback', sa.Text, nullable=True),
    ) 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:21,代碼來源:d2aafa234374_create_error_logs_table.py

示例2: upgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('domains', sa.Column('integration_id', sa.String(length=512), nullable=True))
    op.alter_column('domains', 'total_resource_slots',
                    existing_type=postgresql.JSONB(astext_type=sa.Text()),
                    nullable=True)
    op.add_column('groups', sa.Column('integration_id', sa.String(length=512), nullable=True))
    op.add_column('groups', sa.Column('total_resource_slots',
                                      postgresql.JSONB(astext_type=sa.Text()), nullable=True))
    op.add_column('users', sa.Column('integration_id', sa.String(length=512), nullable=True))
    # ### end Alembic commandk ###

    print('\nSet group\'s total_resource_slots with empty dictionary.')
    query = textwrap.dedent('''\
        UPDATE groups SET total_resource_slots = '{}'::jsonb;
    ''')
    connection = op.get_bind()
    connection.execute(query) 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:20,代碼來源:22964745c12b_add_total_resource_slots_to_group.py

示例3: upgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('key_value_store',
        sa.Column('id', sa.BigInteger(), nullable=False),
        sa.Column('key', sa.Text(), nullable=False),
        sa.Column('value', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
        sa.PrimaryKeyConstraint('id')
    )

    print("Creating index")
    op.create_index(op.f('ix_key_value_store_key'), 'key_value_store', ['key'], unique=True)
    print("Applying not-null constraing")
    op.alter_column('nu_release_item', 'release_date',
               existing_type=postgresql.TIMESTAMP(),
               nullable=False)
    # ### end Alembic commands ### 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:18,代碼來源:00042_49308bd51717_kvstore_table.py

示例4: upgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('fiat_ramp',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('authorising_user_id', sa.Integer(), nullable=True),
    sa.Column('created', sa.DateTime(), nullable=True),
    sa.Column('updated', sa.DateTime(), nullable=True),
    sa.Column('_payment_method', sa.String(), nullable=True),
    sa.Column('payment_amount', sa.Integer(), nullable=True),
    sa.Column('payment_reference', sa.String(), nullable=True),
    sa.Column('payment_status', sa.Enum('PENDING', 'FAILED', 'COMPLETE', name='fiatrampstatusenum'), nullable=True),
    sa.Column('credit_transfer_id', sa.Integer(), nullable=True),
    sa.Column('token_id', sa.Integer(), nullable=True),
    sa.Column('payment_metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.ForeignKeyConstraint(['credit_transfer_id'], ['credit_transfer.id'], ),
    sa.ForeignKeyConstraint(['token_id'], ['token.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ### 
開發者ID:teamsempo,項目名稱:SempoBlockchain,代碼行數:21,代碼來源:cd5cb44c8f7c_.py

示例5: upgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('credit_transfer', sa.Column('transfer_metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True))

    # Create a tempoary "_status" type, convert and drop the "old" type
    tmp_type.create(op.get_bind(), checkfirst=False)
    op.execute('ALTER TABLE credit_transfer ALTER COLUMN transfer_type TYPE _transfertypeenum'
               ' USING transfer_type::text::_transfertypeenum')

    # Convert 'DISBURSEMENT' transfer_type into 'DEPOSIT'
    op.execute(tcr.update().where(tcr.c.transfer_type == u'DISBURSEMENT').values(transfer_type='DEPOSIT'))

    old_type.drop(op.get_bind(), checkfirst=False)
    # Create and convert to the "new" status type
    new_type.create(op.get_bind(), checkfirst=False)
    op.execute('ALTER TABLE credit_transfer ALTER COLUMN transfer_type TYPE transfertypeenum'
               ' USING transfer_type::text::transfertypeenum')
    tmp_type.drop(op.get_bind(), checkfirst=False)
    # ### end Alembic commands ### 
開發者ID:teamsempo,項目名稱:SempoBlockchain,代碼行數:21,代碼來源:1176fec745c0_.py

示例6: upgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def upgrade():
    op.create_table('fda_dap',

        # Meta

        sa.Column('meta_id', sa.Text, unique=True),
        sa.Column('meta_source', sa.Text),
        sa.Column('meta_created', sa.DateTime(timezone=True)),
        sa.Column('meta_updated', sa.DateTime(timezone=True)),

        # General

        sa.Column('id', sa.Text, unique=True),
        sa.Column('documents', JSONB),
        sa.Column('approval_type', sa.Text),
        sa.Column('supplement_number', sa.Integer),
        sa.Column('action_date', sa.Date),
        sa.Column('fda_application_num', sa.Text),
        sa.Column('notes', sa.Text),

    ) 
開發者ID:opentrials,項目名稱:collectors,代碼行數:23,代碼來源:20160725130032_fda_dap_create_table.py

示例7: upgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def upgrade():
### commands auto generated by Alembic - please adjust! ###
    op.create_table('expedition',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('resources_id', sa.Integer(), nullable=True),
    sa.Column('constraints', postgresql.JSONB(), nullable=True),
    sa.ForeignKeyConstraint(['resources_id'], ['resources.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('admiral_j_expedition',
    sa.Column('adm_id', sa.Integer(), nullable=True),
    sa.Column('expedition_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['adm_id'], ['admiral.id'], ),
    sa.ForeignKeyConstraint(['expedition_id'], ['expedition.id'], )
    )
    ### end Alembic commands ### 
開發者ID:KanColleTool,項目名稱:kcsrv,代碼行數:18,代碼來源:ecf3973e1118_add_expedition_table_and_relationship.py

示例8: update_json

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def update_json(self, *args, connection=None, **kwargs):
        t = self.table
        if args:
            if len(args) > 1 and not kwargs:
                field, *path, value = args
            else:
                field, *path = args
                value = kwargs
            for p in reversed(path):
                value = {p: value}
            kwargs = {field: value}
        elif not kwargs:
            raise ValueError('Need args or kwargs')

        await connection.fetchval(
            t.update().where(
                t.c[self.primary_key] == self.pk
            ).values(
                {
                    t.c[field]: sa.func.coalesce(
                        t.c[field], sa.cast({}, JSONB)
                    ) + sa.cast(value, JSONB)
                    for field, value in kwargs.items()
                }
            ).returning(t.c[self.primary_key])) 
開發者ID:dvhb,項目名稱:dvhb-hybrid,代碼行數:27,代碼來源:model.py

示例9: test_compile_jsonb_with_custom_json_encoder

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def test_compile_jsonb_with_custom_json_encoder():
    jsonb_table = sa.Table(
        'meowsb', sa.MetaData(),
        sa.Column('data', postgresql.JSONB),
    )

    class JSONEncoder(json.JSONEncoder):
        def default(self, o):
            if isinstance(o, uuid.UUID):
                return str(o)
            else:
                return super().default(o)

    dialect = connection.get_dialect(
        json_serializer=partial(json.dumps, cls=JSONEncoder)
    )

    data = {
        'uuid4': uuid.uuid4(),
    }
    query = jsonb_table.insert().values(data=data)
    q, p = connection.compile_query(query, dialect=dialect)
    assert q == 'INSERT INTO meowsb (data) VALUES ($1)'
    assert p == ['{"uuid4": "%s"}' % data['uuid4']] 
開發者ID:CanopyTax,項目名稱:asyncpgsa,代碼行數:26,代碼來源:test_connection.py

示例10: upgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def upgrade():
    op.add_column(
        'dataset',
        sa.Column(
            'meta',
            postgresql.JSONB(),
            nullable=True
        )
    )
    op.execute('''
        UPDATE "dataset" SET
            meta = jsonb_set(coalesce(meta, '{}'), '{organization_id}', to_jsonb(organization_id))
        WHERE
            organization_id IS NOT NULL
    ''')
    op.drop_column('dataset', 'organization_id') 
開發者ID:planbrothers,項目名稱:ml-annotate,代碼行數:18,代碼來源:889fee1f3c80_add_meta_to_dataset.py

示例11: upgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('kernels', sa.Column('attached_devices',
                                       postgresql.JSONB(astext_type=sa.Text()),
                                       nullable=True))
    # ### end Alembic commands ### 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:8,代碼來源:9c89b9011872_add_attached_devices_field_in_kernels.py

示例12: downgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'integration_id')
    op.drop_column('groups', 'total_resource_slots')
    op.drop_column('groups', 'integration_id')
    op.alter_column('domains', 'total_resource_slots',
                    existing_type=postgresql.JSONB(astext_type=sa.Text()),
                    nullable=False)
    op.drop_column('domains', 'integration_id')
    # ### end Alembic commands ### 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:12,代碼來源:22964745c12b_add_total_resource_slots_to_group.py

示例13: upgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def upgrade():
    op.add_column('kernels', sa.Column('mount_map', pgsql.JSONB(), nullable=True, default={})) 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:4,代碼來源:d452bacd085c_add_mount_map_column_to_kernel.py

示例14: upgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('kernels', sa.Column('internal_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
    # ### end Alembic commands ### 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:6,代碼來源:202b6dcbc159_add_internal_data_to_kernels.py

示例15: upgrade

# 需要導入模塊: from sqlalchemy.dialects import postgresql [as 別名]
# 或者: from sqlalchemy.dialects.postgresql import JSONB [as 別名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('kernels', sa.Column('resource_opts',
                                       postgresql.JSONB(astext_type=sa.Text()),
                                       nullable=True))
    # ### end Alembic commands ### 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:8,代碼來源:5b45f28d2cac_add_resource_opts_in_kernels.py


注:本文中的sqlalchemy.dialects.postgresql.JSONB屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。