Python sqlalchemy.sql.operators.getitem() Examples
The following are 19
code examples of sqlalchemy.sql.operators.getitem().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sqlalchemy.sql.operators
, or try the search function
.
Example #1
Source File: base.py From jbox with MIT License | 6 votes |
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)
Example #2
Source File: sqltypes.py From sqlalchemy with MIT License | 6 votes |
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
Example #3
Source File: base.py From stdm with GNU General Public License v2.0 | 6 votes |
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)
Example #4
Source File: base.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)
Example #5
Source File: sqltypes.py From planespotter with MIT License | 5 votes |
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
Example #6
Source File: sqltypes.py From pyRevit with GNU General Public License v3.0 | 5 votes |
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
Example #7
Source File: base.py From stdm with GNU General Public License v2.0 | 5 votes |
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)
Example #8
Source File: base.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #9
Source File: base.py From jbox with MIT License | 5 votes |
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)
Example #10
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
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], )
Example #11
Source File: sqltypes.py From jarvis with GNU General Public License v2.0 | 5 votes |
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
Example #12
Source File: base.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
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)
Example #13
Source File: base.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
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)
Example #14
Source File: sqltypes.py From android_universal with MIT License | 5 votes |
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
Example #15
Source File: sqltypes.py From planespotter with MIT License | 4 votes |
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
Example #16
Source File: sqltypes.py From pyRevit with GNU General Public License v3.0 | 4 votes |
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
Example #17
Source File: sqltypes.py From sqlalchemy with MIT License | 4 votes |
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
Example #18
Source File: sqltypes.py From jarvis with GNU General Public License v2.0 | 4 votes |
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
Example #19
Source File: sqltypes.py From android_universal with MIT License | 4 votes |
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