Пример #1
0
    def get_bare_select(self, columns=None):

        if columns is None:
            columns = self.get_fields()

        s = select(columns)

        if self.joins:
            full_join = None
            for j in self.joins:
                if full_join is not None:
                    full_join = full_join.join(*j)
                else:
                    full_join = outerjoin(self.table, *j)
            s = s.select_from(full_join)

        if self.condition is not None:
            s = s.where(self.condition)

        if self.joins:
            if self.group_bys:
                my_group_bys = self.group_bys[:]
            else:
                my_group_bys = []
            for column in columns:
                if not column in my_group_bys and not isinstance(column, SqlFunction):
                    my_group_bys.append(column)
        else:
            my_group_bys = self.group_bys

        if my_group_bys:
            s = s.group_by(*my_group_bys)

        if self.havings:
            for having in self.havings:
                s = s.having(having)

        if self._limit:
            s = s.limit(self._limit)
        if self._offset:
            s = s.offset(self._offset)

        if self.order_bys:
            order_bys = []
            for key, direction in self.order_bys:
                # here we can only perform the ordering by columns that exist in the given query table.
                try:
                    order_bys.append(
                        direction(
                            self.table.c[self.backend.get_column_for_key(self.cls, key)]
                        )
                    )
                except KeyError:
                    continue

                s = s.order_by(*order_bys)

        return s
Пример #2
0
    def get_bare_select(self,columns = None):

        if columns is None:
            columns = self.get_fields()

        s = select(columns)

        if self.joins:
            full_join = None
            for j in self.joins:
                if full_join is not None:
                    full_join = full_join.join(*j)
                else:
                    full_join = outerjoin(self.table,*j)
            s = s.select_from(full_join)

        if self.condition is not None:
            s = s.where(self.condition)

        if self.joins:
            if self.group_bys:
                my_group_bys = self.group_bys[:]
            else:
                my_group_bys = []
            for column in columns:
                if not column in my_group_bys and not isinstance(column,SqlFunction):
                    my_group_bys.append(column)
        else:
            my_group_bys = self.group_bys

        if my_group_bys:
            s = s.group_by(*my_group_bys)

        if self.havings:
            for having in self.havings:
                s = s.having(having)

        if self._limit:
            s = s.limit(self._limit)
        if self._offset:
            s = s.offset(self._offset)

        if self.order_bys:
            order_bys = []
            for key,direction in self.order_bys:
                #here we can only perform the ordering by columns that exist in the given query table.
                try:
                    order_bys.append(direction(self.table.c[self.backend.get_column_for_key(self.cls,key)]))
                except KeyError:
                    continue
                s = s.order_by(*order_bys)

        return s
)

user_role = table(
    'user_roles',
    column('id'),
    column('person_id'),
)

people_table = table(
    'people',
    column('id'),
    column('email'),
)

user_role_join = outerjoin(
    revisions_table, user_role,
    revisions_table.columns.resource_id == user_role.columns.id)


def upgrade():
    connection = op.get_bind()
    revisions = connection.execute(
        select([revisions_table, user_role]).select_from(user_role_join).where(
            and_(revisions_table.columns.resource_type == 'UserRole',
                 revisions_table.columns.content.like(
                     '%"display_name": ""%')))).fetchall()

    for (_id, resource_id, _, action, content, _,
         user_role_person_id) in revisions:
        person_id = None
        content = json.loads(content)
Пример #4
0
)

user_role = table(
    'user_roles',
    column('id'),
    column('person_id'),
)

people_table = table(
    'people',
    column('id'),
    column('email'),
)

user_role_join = outerjoin(
    revisions_table, user_role,
    revisions_table.columns.resource_id == user_role.columns.id)


def upgrade():
  connection = op.get_bind()
  revisions = connection.execute(
      select([revisions_table, user_role]).select_from(user_role_join).where(
          and_(revisions_table.columns.resource_type == 'UserRole',
               revisions_table.columns.content.like('%"display_name": ""%'))
      )).fetchall()

  for (_id, resource_id, _, action, content,
       _, user_role_person_id) in revisions:
    person_id = None
    content = json.loads(content)