MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / index_property

Class index_property

lib/sqlalchemy/ext/indexable.py:251–364  ·  view source on GitHub ↗

A property generator. The generated property describes an object attribute that corresponds to an :class:`_types.Indexable` column. .. seealso:: :mod:`sqlalchemy.ext.indexable`

Source from the content-addressed store, hash-verified

249
250
251class index_property(hybrid_property[_T]):
252 """A property generator. The generated property describes an object
253 attribute that corresponds to an :class:`_types.Indexable`
254 column.
255
256 .. seealso::
257
258 :mod:`sqlalchemy.ext.indexable`
259
260 """
261
262 _NO_DEFAULT_ARGUMENT = cast(_T, object())
263
264 def __init__(
265 self,
266 attr_name: str,
267 index: Union[int, str],
268 default: _T = _NO_DEFAULT_ARGUMENT,
269 datatype: Optional[Callable[[], Any]] = None,
270 mutable: bool = True,
271 onebased: bool = True,
272 ):
273 """Create a new :class:`.index_property`.
274
275 :param attr_name:
276 An attribute name of an `Indexable` typed column, or other
277 attribute that returns an indexable structure.
278 :param index:
279 The index to be used for getting and setting this value. This
280 should be the Python-side index value for integers.
281 :param default:
282 A value which will be returned instead of `AttributeError`
283 when there is not a value at given index.
284 :param datatype: default datatype to use when the field is empty.
285 By default, this is derived from the type of index used; a
286 Python list for an integer index, or a Python dictionary for
287 any other style of index. For a list, the list will be
288 initialized to a list of None values that is at least
289 ``index`` elements long.
290 :param mutable: if False, writes and deletes to the attribute will
291 be disallowed.
292 :param onebased: assume the SQL representation of this value is
293 one-based; that is, the first index in SQL is 1, not zero.
294 """
295
296 if mutable:
297 super().__init__(self.fget, self.fset, self.fdel, self.expr)
298 else:
299 super().__init__(self.fget, None, None, self.expr)
300 self.attr_name = attr_name
301 self.index = index
302 self.default = default
303 is_numeric = isinstance(index, int)
304 onebased = is_numeric and onebased
305
306 if datatype is not None:
307 self.datatype = datatype
308 else:

Callers 5

ArticleClass · 0.90
AClass · 0.90
JClass · 0.90
ArrayClass · 0.90
JsonClass · 0.90

Calls 1

castFunction · 0.50

Tested by

no test coverage detected