我们从Python开源项目中,提取了以下48个代码示例,用于说明如何使用sqlalchemy.orm.join()。
def _splice_into_center(self, other): """Splice a join into the center. Given join(a, b) and join(b, c), return join(a, b).join(c) """ leftmost = other while isinstance(leftmost, sql.Join): leftmost = leftmost.left assert self.right is leftmost left = _ORMJoin( self.left, other.left, self.onclause, isouter=self.isouter, _left_memo=self._left_memo, _right_memo=other._left_memo ) return _ORMJoin( left, other.right, other.onclause, isouter=other.isouter, _right_memo=other._right_memo )
def get_term(message, command): """???????????????????? :param message: slackbot.dispatcher.Message :param str command: ????????? """ name = command.name if command.terms: msg = ['???? `${}` ???? {} ?????'.format( name, len(command.terms))] for t in command.terms: msg.append(t.word) message.send('\n'.join(msg)) else: msg = ('???? `${0}` ??????????????\n' '`${0} add (??)` ????????????'.format(name)) message.send(msg)
def search_term(message, command, keyword): """??????????????????????????????? :param message: slackbot.dispatcher.Message :param str command: ????????? :param str keyword: ????????????????? """ s = Session() terms = (s.query(Term) .filter(Term.create_command == command.id) .filter(Term.word.like('%' + keyword + '%'))) name = command.name if terms.count() > 0: msg = ['???? `${}` ? `{}` ?????? {} ?????'.format( name, keyword, terms.count())] for t in terms: msg.append(t.word) message.send('\n'.join(msg)) else: message.send('???? `${}` ? `{}` ???????????'.format( name, keyword))
def add_term(message, command, word): """???????????? :param message: slackbot.dispatcher.Message :param str command: ????????? :param str word: ?????? """ s = Session() term = (s.query(Term) .select_from(join(Term, CreateCommand)) .filter(CreateCommand.id == command.id) .filter(Term.word == word) .one_or_none()) name = command.name if term: message.send('???? `${}` ??{}????????'.format(name, word)) else: s.add(Term(create_command=command.id, creator=message.body['user'], word=word)) s.commit() message.send('???? `${}` ??{}????????'.format(name, word))
def __new__(cls, value_list): if isinstance(value_list, util.string_types) or value_list is None: return cls.from_string(value_list) values = set(value_list) if values.difference(cls._allowed_cascades): raise sa_exc.ArgumentError( "Invalid cascade option(s): %s" % ", ".join([repr(x) for x in sorted(values.difference(cls._allowed_cascades))])) if "all" in values: values.update(cls._add_w_all_cascades) if "none" in values: values.clear() values.discard('all') self = frozenset.__new__(CascadeOptions, values) self.save_update = 'save-update' in values self.delete = 'delete' in values self.refresh_expire = 'refresh-expire' in values self.merge = 'merge' in values self.expunge = 'expunge' in values self.delete_orphan = "delete-orphan" in values if self.delete_orphan and not self.delete: util.warn("The 'delete-orphan' cascade " "option requires 'delete'.") return self
def __repr__(self): return "CascadeOptions(%r)" % ( ",".join([x for x in sorted(self)]) )
def __repr__(self): if self.with_polymorphic_mappers: with_poly = "(%s)" % ", ".join( mp.class_.__name__ for mp in self.with_polymorphic_mappers) else: with_poly = "" return '<AliasedInsp at 0x%x; %s%s>' % ( id(self), self.class_.__name__, with_poly)
def join(self, right, onclause=None, isouter=False, join_to_left=None): return _ORMJoin(self, right, onclause, isouter)
def outerjoin(left, right, onclause=None, join_to_left=None): """Produce a left outer join between left and right clauses. This is the "outer join" version of the :func:`.orm.join` function, featuring the same behavior except that an OUTER JOIN is generated. See that function's documentation for other usage details. """ return _ORMJoin(left, right, onclause, True)
def __new__(cls, arg): values = set([ c for c in re.split('\s*,\s*', arg or "") if c ]) if values.difference(cls._allowed_cascades): raise sa_exc.ArgumentError( "Invalid cascade option(s): %s" % ", ".join([repr(x) for x in sorted( values.difference(cls._allowed_cascades) )]) ) if "all" in values: values.update(cls._add_w_all_cascades) if "none" in values: values.clear() values.discard('all') self = frozenset.__new__(CascadeOptions, values) self.save_update = 'save-update' in values self.delete = 'delete' in values self.refresh_expire = 'refresh-expire' in values self.merge = 'merge' in values self.expunge = 'expunge' in values self.delete_orphan = "delete-orphan" in values if self.delete_orphan and not self.delete: util.warn("The 'delete-orphan' cascade " "option requires 'delete'.") return self