本文整理汇总了Python中sqlalchemy.dialects.postgresql.json.JSON属性的典型用法代码示例。如果您正苦于以下问题:Python json.JSON属性的具体用法?Python json.JSON怎么用?Python json.JSON使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sqlalchemy.dialects.postgresql.json
的用法示例。
在下文中一共展示了json.JSON属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_default_value_handling
# 需要导入模块: from sqlalchemy.dialects.postgresql import json [as 别名]
# 或者: from sqlalchemy.dialects.postgresql.json import JSON [as 别名]
def setup_default_value_handling(cls):
"""A SQLAlchemy model class decorator that ensures JSON/JSONB default values are correctly handled.
Settings default values for JSON fields have a bunch of issues, because dict and list instances need to be wrapped in ``NestedMutationDict`` and ``NestedMutationList`` that correclty set the parent object dirty state if the container content is modified. This class decorator sets up hooks, so that default values are automatically converted to their wrapped versions.
.. note ::
We are only concerned about initial values. When values are loaded from the database, ``Mutable`` base class of ``NestedMutationDict`` correctly sets up the parent pointers.
.. note ::
This must be applid to the class directly, as SQLAlchemy does not seem ot pick it up if it's applied to an (abstract) parent class.
This might be addressed in future SQLAlchemy / Websauna versions so that we can get rid of this ugly little decorator.
"""
@event.listens_for(cls, "init")
def init(target, args, kwargs):
for c in target.__table__.columns:
if is_json_like_column(c):
default =_get_column_default(target, c)
default = wrap_as_nested(c.name, default, target)
setattr(target, c.name, default)
return cls
示例2: result_processor
# 需要导入模块: from sqlalchemy.dialects.postgresql import json [as 别名]
# 或者: from sqlalchemy.dialects.postgresql.json import JSON [as 别名]
def result_processor(self, dialect, coltype):
if dialect._dbapi_version > (1, 10, 1):
return None # Has native JSON
else:
return super(_PGJSON, self).result_processor(dialect, coltype)
示例3: is_json_like_column
# 需要导入模块: from sqlalchemy.dialects.postgresql import json [as 别名]
# 或者: from sqlalchemy.dialects.postgresql.json import JSON [as 别名]
def is_json_like_column(c: Column) -> bool:
"""Check if the colum."""
return isinstance(c.type, (JSONType, JSON, JSONB))
示例4: init_for_json
# 需要导入模块: from sqlalchemy.dialects.postgresql import json [as 别名]
# 或者: from sqlalchemy.dialects.postgresql.json import JSON [as 别名]
def init_for_json(cls):
"""Check if we need to add JSON column specific SQLAlchemy event listers for this model."""
# import pdb ; pdb.set_trace()
global _loaded_listener
has_json_columns = any([is_json_like_column(c) for c in cls.__table__.columns])
if has_json_columns:
setup_default_value_handling(cls)