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


Python json.JSON属性代码示例

本文整理汇总了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 
开发者ID:websauna,项目名称:websauna,代码行数:27,代码来源:json.py

示例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) 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:7,代码来源:pg8000.py

示例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)) 
开发者ID:websauna,项目名称:websauna,代码行数:5,代码来源:json.py

示例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) 
开发者ID:websauna,项目名称:websauna,代码行数:9,代码来源:json.py


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