本文整理汇总了Python中sqlalchemy.ext.indexable.index_property方法的典型用法代码示例。如果您正苦于以下问题:Python indexable.index_property方法的具体用法?Python indexable.index_property怎么用?Python indexable.index_property使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.ext.indexable
的用法示例。
在下文中一共展示了indexable.index_property方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_index_property
# 需要导入模块: from sqlalchemy.ext import indexable [as 别名]
# 或者: from sqlalchemy.ext.indexable import index_property [as 别名]
def is_index_property(obj: object, name: str) -> bool:
"""Check if an object property is index_property like.
This is needed to correctly generate Colander schema for index_property in SQLAlchemy models.
"""
# http://docs.sqlalchemy.org/en/rel_1_1/changelog/migration_11.html#new-indexable-orm-extension
attr = inspect.getattr_static(obj, name)
return isinstance(attr, index_property)
示例2: __init__
# 需要导入模块: from sqlalchemy.ext import indexable [as 别名]
# 或者: from sqlalchemy.ext.indexable import index_property [as 别名]
def __init__(
self, attr_name, index, default=_NO_DEFAULT_ARGUMENT,
datatype=None, mutable=True, onebased=True):
"""Create a new :class:`.index_property`.
:param attr_name:
An attribute name of an `Indexable` typed column, or other
attribute that returns an indexable structure.
:param index:
The index to be used for getting and setting this value. This
should be the Python-side index value for integers.
:param default:
A value which will be returned instead of `AttributeError`
when there is not a value at given index.
:param datatype: default datatype to use when the field is empty.
By default, this is derived from the type of index used; a
Python list for an integer index, or a Python dictionary for
any other style of index. For a list, the list will be
initialized to a list of None values that is at least
``index`` elements long.
:param mutable: if False, writes and deletes to the attribute will
be disallowed.
:param onebased: assume the SQL representation of this value is
one-based; that is, the first index in SQL is 1, not zero.
"""
if mutable:
super(index_property, self).__init__(
self.fget, self.fset, self.fdel, self.expr
)
else:
super(index_property, self).__init__(
self.fget, None, None, self.expr
)
self.attr_name = attr_name
self.index = index
self.default = default
is_numeric = isinstance(index, int)
onebased = is_numeric and onebased
if datatype is not None:
self.datatype = datatype
else:
if is_numeric:
self.datatype = lambda: [None for x in range(index + 1)]
else:
self.datatype = dict
self.onebased = onebased