本文整理汇总了Python中sqlalchemy.sql.operators.getitem方法的典型用法代码示例。如果您正苦于以下问题:Python operators.getitem方法的具体用法?Python operators.getitem怎么用?Python operators.getitem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.sql.operators
的用法示例。
在下文中一共展示了operators.getitem方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __getitem__
# 需要导入模块: from sqlalchemy.sql import operators [as 别名]
# 或者: from sqlalchemy.sql.operators import getitem [as 别名]
def __getitem__(self, index):
shift_indexes = 1 if self.expr.type.zero_indexes else 0
if isinstance(index, slice):
if shift_indexes:
index = slice(
index.start + shift_indexes,
index.stop + shift_indexes,
index.step
)
index = _Slice(index, self)
return_type = self.type
else:
index += shift_indexes
return_type = self.type.item_type
return default_comparator._binary_operate(
self.expr, operators.getitem, index,
result_type=return_type)
示例2: __getitem__
# 需要导入模块: from sqlalchemy.sql import operators [as 别名]
# 或者: from sqlalchemy.sql.operators import getitem [as 别名]
def __getitem__(self, index):
shift_indexes = 1 if self.expr.type.zero_indexes else 0
if isinstance(index, slice):
if shift_indexes:
index = slice(
index.start + shift_indexes,
index.stop + shift_indexes,
index.step
)
index = _Slice(index, self)
return_type = self.type
else:
index += shift_indexes
return_type = self.type.item_type
return self._binary_operate(self.expr, operators.getitem, index,
result_type=return_type)
示例3: _setup_getitem
# 需要导入模块: from sqlalchemy.sql import operators [as 别名]
# 或者: from sqlalchemy.sql.operators import getitem [as 别名]
def _setup_getitem(self, index):
if isinstance(index, slice):
return_type = self.type
if self.type.zero_indexes:
index = slice(index.start + 1, index.stop + 1, index.step)
slice_ = Slice(
index.start, index.stop, index.step, _name=self.expr.key
)
return operators.getitem, slice_, return_type
else:
if self.type.zero_indexes:
index += 1
if self.type.dimensions is None or self.type.dimensions == 1:
return_type = self.type.item_type
else:
adapt_kw = {"dimensions": self.type.dimensions - 1}
return_type = self.type.adapt(
self.type.__class__, **adapt_kw
)
return operators.getitem, index, return_type
示例4: __init__
# 需要导入模块: from sqlalchemy.sql import operators [as 别名]
# 或者: from sqlalchemy.sql.operators import getitem [as 别名]
def __init__(self, slice_, source_comparator):
self.start = default_comparator._check_literal(
source_comparator.expr,
operators.getitem, slice_.start)
self.stop = default_comparator._check_literal(
source_comparator.expr,
operators.getitem, slice_.stop)
示例5: _setup_getitem
# 需要导入模块: from sqlalchemy.sql import operators [as 别名]
# 或者: from sqlalchemy.sql.operators import getitem [as 别名]
def _setup_getitem(self, index):
if isinstance(index, slice):
return_type = self.type
if self.type.zero_indexes:
index = slice(
index.start + 1,
index.stop + 1,
index.step
)
index = Slice(
_literal_as_binds(
index.start, name=self.expr.key,
type_=type_api.INTEGERTYPE),
_literal_as_binds(
index.stop, name=self.expr.key,
type_=type_api.INTEGERTYPE),
_literal_as_binds(
index.step, name=self.expr.key,
type_=type_api.INTEGERTYPE)
)
else:
if self.type.zero_indexes:
index += 1
if self.type.dimensions is None or self.type.dimensions == 1:
return_type = self.type.item_type
else:
adapt_kw = {'dimensions': self.type.dimensions - 1}
return_type = self.type.adapt(
self.type.__class__, **adapt_kw)
return operators.getitem, index, return_type
示例6: __init__
# 需要导入模块: from sqlalchemy.sql import operators [as 别名]
# 或者: from sqlalchemy.sql.operators import getitem [as 别名]
def __init__(self, slice_, source_comparator):
self.start = source_comparator._check_literal(
source_comparator.expr,
operators.getitem, slice_.start)
self.stop = source_comparator._check_literal(
source_comparator.expr,
operators.getitem, slice_.stop)
示例7: test_no_getitem
# 需要导入模块: from sqlalchemy.sql import operators [as 别名]
# 或者: from sqlalchemy.sql.operators import getitem [as 别名]
def test_no_getitem(self):
assert_raises_message(
NotImplementedError,
"Operator 'getitem' is not supported on this expression",
self.test_operate,
operators.getitem,
column("right"),
)
assert_raises_message(
NotImplementedError,
"Operator 'getitem' is not supported on this expression",
lambda: column("left")[3],
)
示例8: __init__
# 需要导入模块: from sqlalchemy.sql import operators [as 别名]
# 或者: from sqlalchemy.sql.operators import getitem [as 别名]
def __init__(self, slice_, source_comparator):
self.start = source_comparator._check_literal(
source_comparator.expr,
operators.getitem, slice_.start)
self.stop = source_comparator._check_literal(
source_comparator.expr,
operators.getitem, slice_.stop)
示例9: __getitem__
# 需要导入模块: from sqlalchemy.sql import operators [as 别名]
# 或者: from sqlalchemy.sql.operators import getitem [as 别名]
def __getitem__(self, index):
if isinstance(index, slice):
index = _Slice(index, self)
return_type = self.type
else:
return_type = self.type.item_type
return self._binary_operate(self.expr, operators.getitem, index,
result_type=return_type)
示例10: __init__
# 需要导入模块: from sqlalchemy.sql import operators [as 别名]
# 或者: from sqlalchemy.sql.operators import getitem [as 别名]
def __init__(self, item_type, as_tuple=False, dimensions=None,
zero_indexes=False):
"""Construct an :class:`.types.ARRAY`.
E.g.::
Column('myarray', ARRAY(Integer))
Arguments are:
:param item_type: The data type of items of this array. Note that
dimensionality is irrelevant here, so multi-dimensional arrays like
``INTEGER[][]``, are constructed as ``ARRAY(Integer)``, not as
``ARRAY(ARRAY(Integer))`` or such.
:param as_tuple=False: Specify whether return results
should be converted to tuples from lists. This parameter is
not generally needed as a Python list corresponds well
to a SQL array.
:param dimensions: if non-None, the ARRAY will assume a fixed
number of dimensions. This impacts how the array is declared
on the database, how it goes about interpreting Python and
result values, as well as how expression behavior in conjunction
with the "getitem" operator works. See the description at
:class:`.types.ARRAY` for additional detail.
:param zero_indexes=False: when True, index values will be converted
between Python zero-based and SQL one-based indexes, e.g.
a value of one will be added to all index values before passing
to the database.
"""
if isinstance(item_type, ARRAY):
raise ValueError("Do not nest ARRAY types; ARRAY(basetype) "
"handles multi-dimensional arrays of basetype")
if isinstance(item_type, type):
item_type = item_type()
self.item_type = item_type
self.as_tuple = as_tuple
self.dimensions = dimensions
self.zero_indexes = zero_indexes
示例11: __init__
# 需要导入模块: from sqlalchemy.sql import operators [as 别名]
# 或者: from sqlalchemy.sql.operators import getitem [as 别名]
def __init__(
self, item_type, as_tuple=False, dimensions=None, zero_indexes=False
):
"""Construct an :class:`_types.ARRAY`.
E.g.::
Column('myarray', ARRAY(Integer))
Arguments are:
:param item_type: The data type of items of this array. Note that
dimensionality is irrelevant here, so multi-dimensional arrays like
``INTEGER[][]``, are constructed as ``ARRAY(Integer)``, not as
``ARRAY(ARRAY(Integer))`` or such.
:param as_tuple=False: Specify whether return results
should be converted to tuples from lists. This parameter is
not generally needed as a Python list corresponds well
to a SQL array.
:param dimensions: if non-None, the ARRAY will assume a fixed
number of dimensions. This impacts how the array is declared
on the database, how it goes about interpreting Python and
result values, as well as how expression behavior in conjunction
with the "getitem" operator works. See the description at
:class:`_types.ARRAY` for additional detail.
:param zero_indexes=False: when True, index values will be converted
between Python zero-based and SQL one-based indexes, e.g.
a value of one will be added to all index values before passing
to the database.
"""
if isinstance(item_type, ARRAY):
raise ValueError(
"Do not nest ARRAY types; ARRAY(basetype) "
"handles multi-dimensional arrays of basetype"
)
if isinstance(item_type, type):
item_type = item_type()
self.item_type = item_type
self.as_tuple = as_tuple
self.dimensions = dimensions
self.zero_indexes = zero_indexes