本文整理汇总了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
示例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",
)
示例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 ###
示例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)
示例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 ###
示例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 ###
示例7: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import JSON [as 别名]
def upgrade():
op.add_column('kernels', sa.Column('service_ports', sa.JSON(), nullable=True))
示例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
示例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))
示例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 ###
示例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 ###
示例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')
)
示例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
示例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),
)
示例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)