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


Python sqlalchemy.JSON属性代码示例

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


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

示例1: get_model_search_filter

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def get_model_search_filter(Model):
    mapper = inspect(Model)

    class ModelSearchFilter(CharFilter):
        def filter(self, qs, value):
            value = self.clean_value(value)
            if value in EMPTY_VALUES:
                return qs

            def map_column(column):
                if isinstance(column.type, (sqlalchemy.Integer, sqlalchemy.Numeric)):
                    return cast(column, sqlalchemy.String).__eq__(value)
                elif isinstance(column.type, sqlalchemy.String):
                    return column.ilike('%{}%'.format(value))
                elif isinstance(column.type, sqlalchemy.JSON):
                    return cast(column, sqlalchemy.String).ilike('%{}%'.format(value))

            operators = list(filter(lambda x: x is not None, map(map_column, mapper.columns)))

            return qs.filter(or_(*operators))

    return ModelSearchFilter 
开发者ID:jet-admin,项目名称:jet-bridge,代码行数:24,代码来源:model_search.py

示例2: test_change_type

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def test_change_type(self):
        context = self._fixture()
        self.table.append_column(Column("toj", Text))
        self.table.append_column(Column("fromj", JSON))
        with self.op.batch_alter_table(
            "foo", copy_from=self.table
        ) as batch_op:
            batch_op.alter_column("data", type_=Integer)
            batch_op.alter_column("toj", type_=JSON)
            batch_op.alter_column("fromj", type_=Text)
        context.assert_(
            "CREATE TABLE _alembic_tmp_foo (id INTEGER NOT NULL, "
            "data INTEGER, x INTEGER, toj JSON, fromj TEXT, PRIMARY KEY (id))",
            "INSERT INTO _alembic_tmp_foo (id, data, x, toj, fromj) "
            "SELECT foo.id, "
            "CAST(foo.data AS INTEGER) AS %s, foo.x, foo.toj, "
            "CAST(foo.fromj AS TEXT) AS %s FROM foo"
            % (
                ("data" if sqla_14 else "anon_1"),
                ("fromj" if sqla_14 else "anon_2"),
            ),
            "DROP TABLE foo",
            "ALTER TABLE _alembic_tmp_foo RENAME TO foo",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:26,代码来源:test_batch.py

示例3: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('notifications',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(length=1000), nullable=True),
    sa.Column('provider', sa.String(length=10000), nullable=True),
    sa.Column('data', sa.JSON(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='SET NULL'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_notifications_id'), 'notifications', ['id'], unique=False)
    op.create_index(op.f('ix_notifications_name'), 'notifications', ['name'], unique=False)
    op.create_table('notificationsxstores',
    sa.Column('notification_id', sa.Integer(), nullable=True),
    sa.Column('store_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['notification_id'], ['notifications.id'], ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['store_id'], ['stores.id'], ondelete='SET NULL')
    )
    # ### end Alembic commands ### 
开发者ID:MrNaif2018,项目名称:bitcart,代码行数:22,代码来源:bbeb9365b195_added_notifications.py

示例4: test_variant_righthand_coercion_honors_wrapped

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def test_variant_righthand_coercion_honors_wrapped(self):
        my_json_normal = JSON()
        my_json_variant = JSON().with_variant(String(), "sqlite")

        tab = table(
            "test",
            column("avalue", my_json_normal),
            column("bvalue", my_json_variant),
        )
        expr = tab.c.avalue["foo"] == "bar"

        is_(expr.right.type._type_affinity, String)
        is_not_(expr.right.type, my_json_normal)

        expr = tab.c.bvalue["foo"] == "bar"

        is_(expr.right.type._type_affinity, String)
        is_not_(expr.right.type, my_json_variant) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_types.py

示例5: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column("collection", sa.Column("description", sa.String(), nullable=True))

    op.add_column("collection", sa.Column("group", sa.String(), nullable=False, server_default="default"))
    op.alter_column("collection", "group", server_default=None)

    op.add_column("collection", sa.Column("view_url_hdf5", sa.String(), nullable=True))
    op.add_column("collection", sa.Column("view_url_plaintext", sa.String(), nullable=True))
    op.add_column("collection", sa.Column("view_metadata", sa.JSON(), nullable=True))

    op.add_column("collection", sa.Column("view_available", sa.Boolean(), nullable=True))
    op.execute("UPDATE collection SET view_available=false")
    op.alter_column("collection", "view_available", nullable=False)

    op.add_column("collection", sa.Column("visibility", sa.Boolean(), nullable=True))
    op.execute("UPDATE collection SET visibility=true")
    op.alter_column("collection", "visibility", nullable=False)
    # ### end Alembic commands ### 
开发者ID:MolSSI,项目名称:QCFractal,代码行数:21,代码来源:a2f76bb7be65_updates_collections_table_with_owner_.py

示例6: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('job',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('created_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=False),
    sa.Column('updated_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True),
    sa.Column('name', sa.String(length=128), nullable=False),
    sa.Column('payload', sa.JSON(), nullable=True),
    sa.Column('taken', sa.Boolean(), nullable=False),
    sa.Column('run_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ### 
开发者ID:simple-login,项目名称:app,代码行数:15,代码来源:2020_020313_9c976df9b9c4_.py

示例7: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def upgrade():
    op.add_column('kernels', sa.Column('service_ports', sa.JSON(), nullable=True)) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:4,代码来源:0e558d06e0e3_add_service_ports.py

示例8: list_dids_by_meta

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def list_dids_by_meta(scope, select, session=None):
    """
    Add or update the given metadata to the given did

    :param scope: the scope of the did
    :param name: the name of the did
    :param meta: the metadata to be added or updated
    """
    # Currently for sqlite only add, get and delete is implemented.
    if session.bind.dialect.name == 'sqlite':
        raise NotImplementedError
    if session.bind.dialect.name == 'oracle':
        oracle_version = int(session.connection().connection.version.split('.')[0])
        if oracle_version < 12:
            raise NotImplementedError

    query = session.query(models.DidMeta)
    if scope is not None:
        query = query.filter(models.DidMeta.scope == scope)

    for k, v in iteritems(select):
        if session.bind.dialect.name == 'oracle':
            query = query.filter(text("json_exists(meta,'$.%s?(@==''%s'')')" % (k, v)))
        else:
            query = query.filter(cast(models.DidMeta.meta[k], String) == type_coerce(v, JSON))
    dids = list()
    for row in query.yield_per(10):
        dids.append({'scope': row.scope, 'name': row.name})
    return dids 
开发者ID:rucio,项目名称:rucio,代码行数:31,代码来源:did.py

示例9: filter_search_field

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def filter_search_field(field):
    allowed_fields = [
        sqlalchemy.String,
        sqlalchemy.JSON,
    ]

    return isinstance(field.type, tuple(allowed_fields)) 
开发者ID:jet-admin,项目名称:jet-bridge,代码行数:9,代码来源:model_relation.py

示例10: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('tasks',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('entry_name', sa.String(length=100), nullable=True),
    sa.Column('task_name', sa.String(length=100), nullable=False),
    sa.Column('config', sa.JSON(), nullable=True),
    sa.Column('cron', sa.String(length=100), nullable=True),
    sa.Column('is_removed', sa.Boolean(), nullable=False),
    sa.Column('is_auto_created', sa.Boolean(), nullable=False),
    sa.Column('is_manually_modified', sa.Boolean(), nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_tasks'))
    )
    op.create_index(op.f('ix_tasks_entry_name'), 'tasks', ['entry_name'], unique=False)
    op.create_index(op.f('ix_tasks_is_auto_created'), 'tasks', ['is_auto_created'], unique=False)
    op.create_index(op.f('ix_tasks_is_removed'), 'tasks', ['is_removed'], unique=False)
    op.create_index(op.f('ix_tasks_is_manually_modified'), 'tasks', ['is_manually_modified'], unique=False)
    op.create_index(op.f('ix_tasks_task_name'), 'tasks', ['task_name'], unique=False)
    op.create_table('taskexecutions',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('task_id', sa.Integer(), nullable=False),
    sa.Column('planned_at', postgresql.TIMESTAMP(timezone=True), nullable=False),
    sa.Column('locked_at', postgresql.TIMESTAMP(timezone=True), nullable=True),
    sa.Column('finished_at', postgresql.TIMESTAMP(timezone=True), nullable=True),
    sa.Column('canceled_at', postgresql.TIMESTAMP(timezone=True), nullable=True),
    sa.Column('log', sa.String(), nullable=True),
    sa.Column('success', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['task_id'], ['tasks.id'], name=op.f('fk_taskexecutions_task_id_tasks'), ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_taskexecutions'))
    )
    op.create_index(op.f('ix_taskexecutions_canceled_at'), 'taskexecutions', ['canceled_at'], unique=False)
    op.create_index(op.f('ix_taskexecutions_finished_at'), 'taskexecutions', ['finished_at'], unique=False)
    op.create_index(op.f('ix_taskexecutions_locked_at'), 'taskexecutions', ['locked_at'], unique=False)
    op.create_index(op.f('ix_taskexecutions_planned_at'), 'taskexecutions', ['planned_at'], unique=False)
    op.create_index(op.f('ix_taskexecutions_success'), 'taskexecutions', ['success'], unique=False)
    op.create_index(op.f('ix_taskexecutions_task_id'), 'taskexecutions', ['task_id'], unique=False)
    op.add_column('achievements', sa.Column('evaluation_shift', sa.Integer(), nullable=True))
    ### end Alembic commands ### 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:40,代码来源:a90076b18837_tasks_and_shift.py

示例11: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('additional_public_data', sa.JSON(), nullable=True))
    ### end Alembic commands ### 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:6,代码来源:3512efb5496d_additional_public_data.py

示例12: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def upgrade():
    """Apply Add RenderedTaskInstanceFields table"""
    json_type = sa.JSON
    conn = op.get_bind()  # pylint: disable=no-member

    if conn.dialect.name != "postgresql":
        # Mysql 5.7+/MariaDB 10.2.3 has JSON support. Rather than checking for
        # versions, check for the function existing.
        try:
            conn.execute("SELECT JSON_VALID(1)").fetchone()
        except (sa.exc.OperationalError, sa.exc.ProgrammingError):
            json_type = sa.Text

    op.create_table(
        TABLE_NAME,  # pylint: disable=no-member
        sa.Column('dag_id', sa.String(length=250), nullable=False),
        sa.Column('task_id', sa.String(length=250), nullable=False),
        sa.Column('execution_date', sa.TIMESTAMP(timezone=True), nullable=False),
        sa.Column('rendered_fields', json_type(), nullable=False),
        sa.PrimaryKeyConstraint('dag_id', 'task_id', 'execution_date')
    ) 
开发者ID:apache,项目名称:airflow,代码行数:23,代码来源:852ae6c715af_add_rendered_task_instance_fields_table.py

示例13: cast_for_batch_migrate

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def cast_for_batch_migrate(self, existing, existing_transfer, new_type):
        if (
            existing.type._type_affinity is not new_type._type_affinity
            and not isinstance(new_type, JSON)
        ):
            existing_transfer["expr"] = cast(
                existing_transfer["expr"], new_type
            )


# @compiles(AddColumn, 'sqlite')
# def visit_add_column(element, compiler, **kw):
#    return "%s %s" % (
#        alter_table(compiler, element.table_name, element.schema),
#        add_column(compiler, element.column, **kw)
#    )


# def add_column(compiler, column, **kw):
#    text = "ADD COLUMN %s" % compiler.get_column_specification(column, **kw)
# need to modify SQLAlchemy so that the CHECK associated with a Boolean
# or Enum gets placed as part of the column constraints, not the Table
# see ticket 98
#    for const in column.constraints:
#        text += compiler.process(AddConstraint(const))
#    return text 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:28,代码来源:sqlite.py

示例14: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def upgrade():
    op.create_table(
        "git_projects",
        sa.Column("id", sa.Integer, primary_key=True),
        sa.Column("namespace", sa.String, index=True),
        sa.Column("repo_name", sa.String, index=True),
    )
    op.create_table(
        "pull_requests",
        sa.Column("id", sa.Integer, primary_key=True),
        sa.Column("pr_id", sa.Integer, index=True),
        sa.Column("project_id", sa.Integer, sa.ForeignKey("git_projects.id")),
        sa.ForeignKeyConstraint(("project_id",), ["git_projects.id"],),
    )
    op.create_table(
        "srpm_builds",
        sa.Column("id", sa.Integer, primary_key=True),
        sa.Column("logs", sa.Text),
    )
    op.create_table(
        "copr_builds",
        sa.Column("id", sa.Integer, primary_key=True),
        sa.Column("build_id", sa.String, index=True),
        sa.Column("pr_id", sa.Integer, sa.ForeignKey("pull_requests.id")),
        sa.ForeignKeyConstraint(("pr_id",), ["pull_requests.id"],),
        sa.Column("srpm_build_id", sa.Integer, sa.ForeignKey("srpm_builds.id")),
        sa.ForeignKeyConstraint(("srpm_build_id",), ["srpm_builds.id"],),
        sa.Column("logs", sa.Text),
        sa.Column("commit_sha", sa.String),
        sa.Column("status", sa.String),
        sa.Column("target", sa.String),
        sa.Column("web_url", sa.String),
        sa.Column("build_logs_url", sa.String),
        sa.Column("data", sa.JSON),
    ) 
开发者ID:packit-service,项目名称:packit-service,代码行数:37,代码来源:258490f6e667_initial_schema.py

示例15: load_dialect_impl

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def load_dialect_impl(self, dialect):
        """This is an end-user override hook that can be used to provide
        differing types depending on the given dialect.

        Args:
            dialect (object): SQLAlchemy dialect object
        Returns:
            object: if dialect name is 'mysql' it will override the type descriptor to JSON()
        """
        if dialect.name == "mysql":
            return dialect.type_descriptor(JSON())
        return dialect.type_descriptor(self.impl) 
开发者ID:spotify,项目名称:comet-core,代码行数:14,代码来源:model.py


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