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