Python sqlalchemy.sql.operators.add() Examples
The following are 30
code examples of sqlalchemy.sql.operators.add().
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: sqltypes.py From sqlalchemy with MIT License | 6 votes |
def _expression_adaptations(self): # TODO: need a dictionary object that will # handle operators generically here, this is incomplete return { operators.add: { Date: Date, Integer: self.__class__, Numeric: Numeric, }, operators.mul: { Interval: Interval, Integer: self.__class__, Numeric: Numeric, }, operators.div: {Integer: self.__class__, Numeric: Numeric}, operators.truediv: {Integer: self.__class__, Numeric: Numeric}, operators.sub: {Integer: self.__class__, Numeric: Numeric}, }
Example #2
Source File: test_query.py From sqlalchemy with MIT License | 6 votes |
def test_filter_with_detached_non_pk_col_has_value(self): self._fixture1() Dingaling, HasDingaling = ( self.classes.Dingaling, self.classes.HasDingaling, ) s = Session() d = Dingaling(data="some data") s.add(d) s.commit() s.expire(d) assert "data" not in d.__dict__ q = s.query(HasDingaling).filter_by(dingaling=d) self.assert_compile( q, "SELECT has_dingaling.id AS has_dingaling_id, " "has_dingaling.dingaling_id AS has_dingaling_dingaling_id " "FROM has_dingaling WHERE :param_1 = " "has_dingaling.dingaling_id AND :param_2 = :data_1", checkparams={"param_1": 1, "param_2": "some data", "data_1": "hi"}, )
Example #3
Source File: test_query.py From sqlalchemy with MIT License | 6 votes |
def test_filter_with_persistent_non_pk_col_is_default_null(self): # test #4676 - comparison to a persistent column that is # NULL in the database, but is not fetched self._fixture1() Dingaling, HasDingaling = ( self.classes.Dingaling, self.classes.HasDingaling, ) s = Session() d = Dingaling(id=1) s.add(d) s.flush() assert "data" not in d.__dict__ q = s.query(HasDingaling).filter_by(dingaling=d) with expect_warnings("Got None for value of column"): self.assert_compile( q, "SELECT has_dingaling.id AS has_dingaling_id, " "has_dingaling.dingaling_id AS has_dingaling_dingaling_id " "FROM has_dingaling WHERE :param_1 = " "has_dingaling.dingaling_id AND :param_2 = :data_1", checkparams={"param_1": 1, "param_2": None, "data_1": "hi"}, )
Example #4
Source File: test_query.py From sqlalchemy with MIT License | 6 votes |
def test_with_pending_autoflush(self): Order, User = self.classes.Order, self.classes.User sess = Session() o1 = sess.query(Order).first() opending = Order(id=20, user_id=o1.user_id) sess.add(opending) eq_( sess.query(User).with_parent(opending, "user").one(), User(id=o1.user_id), ) eq_( sess.query(User).filter(with_parent(opending, "user")).one(), User(id=o1.user_id), )
Example #5
Source File: test_query.py From sqlalchemy with MIT License | 6 votes |
def test_related_eagerload_against_text(self, add_columns, loader_option): # new in 1.4. textual selects have columns so subqueryloaders # and selectinloaders can join onto them. we add columns # automatiacally to TextClause as well, however subqueryloader # is not working at the moment due to execution model refactor, # it creates a subquery w/ adapter before those columns are # available. this is a super edge case and as we want to rewrite # the loaders to use select(), maybe we can get it then. User = self.classes.User text_clause = text("select * from users") if add_columns: text_clause = text_clause.columns(User.id, User.name) s = create_session() q = ( s.query(User) .from_statement(text_clause) .options(loader_option(User.addresses)) ) def go(): eq_(set(q.all()), set(self.static.user_address_result)) self.assert_sql_count(testing.db, go, 2)
Example #6
Source File: test_operators.py From sqlalchemy with MIT License | 6 votes |
def test_concatenable_adapt(self): class TypeOne(Concatenable, TypeEngine): pass class TypeTwo(Concatenable, TypeEngine): pass class TypeThree(TypeEngine): pass expr = column("x", TypeOne()) - column("y", TypeTwo()) is_(expr.type._type_affinity, TypeOne) is_(expr.operator, operator.sub) expr = column("x", TypeOne()) + column("y", TypeTwo()) is_(expr.type._type_affinity, TypeOne) is_(expr.operator, operators.concat_op) expr = column("x", TypeOne()) - column("y", TypeThree()) is_(expr.type._type_affinity, TypeOne) is_(expr.operator, operator.sub) expr = column("x", TypeOne()) + column("y", TypeThree()) is_(expr.type._type_affinity, TypeOne) is_(expr.operator, operator.add)
Example #7
Source File: sqltypes.py From jarvis with GNU General Public License v2.0 | 6 votes |
def _expression_adaptations(self): return { operators.mul: { Interval: Interval, Numeric: self.__class__, Integer: self.__class__, }, operators.div: { Numeric: self.__class__, Integer: self.__class__, }, operators.truediv: { Numeric: self.__class__, Integer: self.__class__, }, operators.add: { Numeric: self.__class__, Integer: self.__class__, }, operators.sub: { Numeric: self.__class__, Integer: self.__class__, } }
Example #8
Source File: test_types.py From sqlalchemy with MIT License | 6 votes |
def _all_types(omit_special_types=False): seen = set() for typ in _types_for_mod(types): if omit_special_types and typ in ( types.TypeDecorator, types.TypeEngine, types.Variant, ): continue if typ in seen: continue seen.add(typ) yield typ for dialect in _all_dialect_modules(): for typ in _types_for_mod(dialect): if typ in seen: continue seen.add(typ) yield typ
Example #9
Source File: sqltypes.py From sqlalchemy with MIT License | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Date: DateTime, Interval: self.__class__, DateTime: DateTime, Time: Time, }, operators.sub: {Interval: self.__class__}, operators.mul: {Numeric: self.__class__}, operators.truediv: {Numeric: self.__class__}, operators.div: {Numeric: self.__class__}, }
Example #10
Source File: sqltypes.py From sqlalchemy with MIT License | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Integer: self.__class__, Interval: DateTime, Time: DateTime, }, operators.sub: { # date - integer = date Integer: self.__class__, # date - date = integer. Date: Integer, Interval: DateTime, # date - datetime = interval, # this one is not in the PG docs # but works DateTime: Interval, }, }
Example #11
Source File: sqltypes.py From jarvis with GNU General Public License v2.0 | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Integer: self.__class__, Interval: DateTime, Time: DateTime, }, operators.sub: { # date - integer = date Integer: self.__class__, # date - date = integer. Date: Integer, Interval: DateTime, # date - datetime = interval, # this one is not in the PG docs # but works DateTime: Interval, }, }
Example #12
Source File: sqltypes.py From jarvis with GNU General Public License v2.0 | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Date: DateTime, Interval: self.__class__, DateTime: DateTime, Time: Time, }, operators.sub: { Interval: self.__class__ }, operators.mul: { Numeric: self.__class__ }, operators.truediv: { Numeric: self.__class__ }, operators.div: { Numeric: self.__class__ } }
Example #13
Source File: sqltypes.py From pyRevit with GNU General Public License v3.0 | 6 votes |
def _expression_adaptations(self): return { operators.add: { Date: DateTime, Interval: self.__class__, DateTime: DateTime, Time: Time, }, operators.sub: { Interval: self.__class__ }, operators.mul: { Numeric: self.__class__ }, operators.truediv: { Numeric: self.__class__ }, operators.div: { Numeric: self.__class__ } }
Example #14
Source File: sqltypes.py From pyRevit with GNU General Public License v3.0 | 6 votes |
def _expression_adaptations(self): return { operators.mul: { Interval: Interval, Numeric: self.__class__, }, operators.div: { Numeric: self.__class__, }, operators.truediv: { Numeric: self.__class__, }, operators.add: { Numeric: self.__class__, }, operators.sub: { Numeric: self.__class__, } }
Example #15
Source File: sqltypes.py From pyRevit with GNU General Public License v3.0 | 6 votes |
def _expression_adaptations(self): return { operators.mul: { Interval: Interval, Numeric: self.__class__, Integer: self.__class__, }, operators.div: { Numeric: self.__class__, Integer: self.__class__, }, operators.truediv: { Numeric: self.__class__, Integer: self.__class__, }, operators.add: { Numeric: self.__class__, Integer: self.__class__, }, operators.sub: { Numeric: self.__class__, Integer: self.__class__, } }
Example #16
Source File: sqltypes.py From android_universal with MIT License | 6 votes |
def _expression_adaptations(self): return { operators.mul: { Interval: Interval, Numeric: self.__class__, Integer: self.__class__, }, operators.div: { Numeric: self.__class__, Integer: self.__class__, }, operators.truediv: { Numeric: self.__class__, Integer: self.__class__, }, operators.add: { Numeric: self.__class__, Integer: self.__class__, }, operators.sub: { Numeric: self.__class__, Integer: self.__class__, } }
Example #17
Source File: sqltypes.py From planespotter with MIT License | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Date: DateTime, Interval: self.__class__, DateTime: DateTime, Time: Time, }, operators.sub: { Interval: self.__class__ }, operators.mul: { Numeric: self.__class__ }, operators.truediv: { Numeric: self.__class__ }, operators.div: { Numeric: self.__class__ } }
Example #18
Source File: sqltypes.py From planespotter with MIT License | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Integer: self.__class__, Interval: DateTime, Time: DateTime, }, operators.sub: { # date - integer = date Integer: self.__class__, # date - date = integer. Date: Integer, Interval: DateTime, # date - datetime = interval, # this one is not in the PG docs # but works DateTime: Interval, }, }
Example #19
Source File: sqltypes.py From android_universal with MIT License | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Integer: self.__class__, Interval: DateTime, Time: DateTime, }, operators.sub: { # date - integer = date Integer: self.__class__, # date - date = integer. Date: Integer, Interval: DateTime, # date - datetime = interval, # this one is not in the PG docs # but works DateTime: Interval, }, }
Example #20
Source File: sqltypes.py From planespotter with MIT License | 6 votes |
def _expression_adaptations(self): return { operators.mul: { Interval: Interval, Numeric: self.__class__, Integer: self.__class__, }, operators.div: { Numeric: self.__class__, Integer: self.__class__, }, operators.truediv: { Numeric: self.__class__, Integer: self.__class__, }, operators.add: { Numeric: self.__class__, Integer: self.__class__, }, operators.sub: { Numeric: self.__class__, Integer: self.__class__, } }
Example #21
Source File: sqltypes.py From android_universal with MIT License | 6 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Date: DateTime, Interval: self.__class__, DateTime: DateTime, Time: Time, }, operators.sub: { Interval: self.__class__ }, operators.mul: { Numeric: self.__class__ }, operators.truediv: { Numeric: self.__class__ }, operators.div: { Numeric: self.__class__ } }
Example #22
Source File: sqltypes.py From android_universal with MIT License | 5 votes |
def _adapt_expression(self, op, other_comparator): if (op is operators.add and isinstance( other_comparator, (Concatenable.Comparator, NullType.Comparator) )): return operators.concat_op, self.expr.type else: return super(Concatenable.Comparator, self)._adapt_expression( op, other_comparator)
Example #23
Source File: sqltypes.py From planespotter with MIT License | 5 votes |
def _expression_adaptations(self): # TODO: need a dictionary object that will # handle operators generically here, this is incomplete return { operators.add: { Date: Date, Integer: self.__class__, Numeric: Numeric, }, operators.mul: { Interval: Interval, Integer: self.__class__, Numeric: Numeric, }, operators.div: { Integer: self.__class__, Numeric: Numeric, }, operators.truediv: { Integer: self.__class__, Numeric: Numeric, }, operators.sub: { Integer: self.__class__, Numeric: Numeric, }, }
Example #24
Source File: sqltypes.py From android_universal with MIT License | 5 votes |
def _expression_adaptations(self): # TODO: need a dictionary object that will # handle operators generically here, this is incomplete return { operators.add: { Date: Date, Integer: self.__class__, Numeric: Numeric, }, operators.mul: { Interval: Interval, Integer: self.__class__, Numeric: Numeric, }, operators.div: { Integer: self.__class__, Numeric: Numeric, }, operators.truediv: { Integer: self.__class__, Numeric: Numeric, }, operators.sub: { Integer: self.__class__, Numeric: Numeric, }, }
Example #25
Source File: sqltypes.py From jarvis with GNU General Public License v2.0 | 5 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Interval: self.__class__, }, operators.sub: { Interval: self.__class__, DateTime: Interval, }, }
Example #26
Source File: sqltypes.py From android_universal with MIT License | 5 votes |
def _expression_adaptations(self): # Based on http://www.postgresql.org/docs/current/\ # static/functions-datetime.html. return { operators.add: { Interval: self.__class__, }, operators.sub: { Interval: self.__class__, DateTime: Interval, }, }
Example #27
Source File: sqltypes.py From jarvis with GNU General Public License v2.0 | 5 votes |
def _expression_adaptations(self): # TODO: need a dictionary object that will # handle operators generically here, this is incomplete return { operators.add: { Date: Date, Integer: self.__class__, Numeric: Numeric, }, operators.mul: { Interval: Interval, Integer: self.__class__, Numeric: Numeric, }, operators.div: { Integer: self.__class__, Numeric: Numeric, }, operators.truediv: { Integer: self.__class__, Numeric: Numeric, }, operators.sub: { Integer: self.__class__, Numeric: Numeric, }, }
Example #28
Source File: sqltypes.py From jarvis with GNU General Public License v2.0 | 5 votes |
def _adapt_expression(self, op, other_comparator): if (op is operators.add and isinstance( other_comparator, (Concatenable.Comparator, NullType.Comparator) )): return operators.concat_op, self.expr.type else: return super(Concatenable.Comparator, self)._adapt_expression( op, other_comparator)
Example #29
Source File: test_query.py From sqlalchemy with MIT License | 5 votes |
def test_filter_with_detached_non_pk_col_is_default_null(self): self._fixture1() Dingaling, HasDingaling = ( self.classes.Dingaling, self.classes.HasDingaling, ) s = Session() d = Dingaling() s.add(d) s.flush() s.commit() d.id s.expire(d, ["data"]) s.expunge(d) assert "data" not in d.__dict__ assert "id" in d.__dict__ q = s.query(HasDingaling).filter_by(dingaling=d) # this case we still can't handle, object is detached so we assume # nothing assert_raises_message( sa_exc.StatementError, r"Can't resolve value for column dingalings.data on " r"object .*Dingaling.* the object is detached and " r"the value was expired", q.all, )
Example #30
Source File: test_query.py From sqlalchemy with MIT License | 5 votes |
def test_with_pending_no_autoflush(self): Order, User = self.classes.Order, self.classes.User sess = Session(autoflush=False) o1 = sess.query(Order).first() opending = Order(user_id=o1.user_id) sess.add(opending) eq_( sess.query(User).with_parent(opending, "user").one(), User(id=o1.user_id), )