本文整理汇总了Python中sqlalchemy.ext.mutable.MutableDict.as_mutable方法的典型用法代码示例。如果您正苦于以下问题:Python MutableDict.as_mutable方法的具体用法?Python MutableDict.as_mutable怎么用?Python MutableDict.as_mutable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.ext.mutable.MutableDict
的用法示例。
在下文中一共展示了MutableDict.as_mutable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure_columns
# 需要导入模块: from sqlalchemy.ext.mutable import MutableDict [as 别名]
# 或者: from sqlalchemy.ext.mutable.MutableDict import as_mutable [as 别名]
def configure_columns(self):
class CustomPickleType(PickleType):
if self.dialect == "mysql":
impl = MSMediumBlob
self.Dict = MutableDict.as_mutable(CustomPickleType)
self.List = MutableList.as_mutable(CustomPickleType)
if self.dialect == "postgresql":
self.LargeString = Text
else:
self.LargeString = Text(settings["database"]["large_string_length"])
self.SmallString = String(settings["database"]["small_string_length"])
default_ctypes = {
self.Dict: {},
self.List: [],
self.LargeString: "",
self.SmallString: "",
Text: "",
}
class CustomColumn(Column):
def __init__(self, ctype, *args, **kwargs):
if "default" not in kwargs and ctype in default_ctypes:
kwargs["default"] = default_ctypes[ctype]
super().__init__(ctype, *args, **kwargs)
self.Column = CustomColumn
示例2: define_tables
# 需要导入模块: from sqlalchemy.ext.mutable import MutableDict [as 别名]
# 或者: from sqlalchemy.ext.mutable.MutableDict import as_mutable [as 别名]
def define_tables(cls, metadata):
MutableDict = cls._type_fixture()
mutable_pickle = MutableDict.as_mutable(PickleType)
Table(
"foo",
metadata,
Column(
"id", Integer, primary_key=True, test_needs_autoincrement=True
),
Column("data", mutable_pickle, default={}),
)