當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。