本文整理匯總了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)