コード例 #1
0
ファイル: thing.py プロジェクト: xxl007/reddit
    def _cursor(self):
        #TODO why was this even here?
        #get_cols = bool(self._sort_param)
        get_cols = False
        params = (self._kind._type_id, get_cols, self._sort, self._limit,
                  self._offset, self._rules)
        if self._use_data:
            c = tdb.find_data(*params)
        else:
            c = tdb.find_things(*params)

        #TODO simplfy this! get_cols is always false?
        #called on a bunch of rows to fetch their properties in batch
        def row_fn(rows):
            #if have a sort, add the sorted column to the results
            if get_cols:
                extra_props = {}
                for r in rows:
                    for sc in (s.col for s in self._sort):
                        #dict of ids to the extra sort params
                        props = extra_props.setdefault(r.thing_id, {})
                        props[sc] = getattr(r, sc)
                _ids = extra_props.keys()
            else:
                _ids = rows
                extra_props = {}
            return self._kind._byID(_ids,
                                    data=self._data,
                                    return_dict=False,
                                    stale=self._stale,
                                    extra_props=extra_props)

        return Results(c, row_fn, True)
コード例 #2
0
 def _cursor(self):
     c = tdb.find_rels(self._kind._type_id,
                       False,
                       sort=self._sort,
                       limit=self._limit,
                       constraints=self._rules)
     return Results(c, self._make_rel, True)
コード例 #3
0
ファイル: thing.py プロジェクト: Elenw/reddit
 def _cursor(self):
     c = tdb.find_rels(
         ret_props=["_rel_id"],
         rel_type_id=self._kind._type_id,
         sort=self._sort,
         limit=self._limit,
         offset=self._offset,
         constraints=self._rules,
     )
     return Results(c, self._make_rel, do_batch=True)
コード例 #4
0
ファイル: thing.py プロジェクト: iamaviator/reddit
    def _cursor(self):
        if self._use_data:
            find_fn = tdb.find_data
        else:
            find_fn = tdb.find_things

        cursor = find_fn(
            type_id=self._kind._type_id,
            sort=self._sort,
            limit=self._limit,
            offset=self._offset,
            constraints=self._rules,
        )

        #called on a bunch of rows to fetch their properties in batch
        def row_fn(ids):
            return self._kind._byID(ids, return_dict=False, stale=self._stale)

        return Results(cursor, row_fn, do_batch=True)
コード例 #5
0
    try:
        r = add_request_info(s).execute()
    except Exception, e:
        dbm.mark_dead(r_table.bind)
        # this thread must die so that others may live
        raise

    def build_fn(row):
        # return Storage objects with just the requested props
        props = {}
        for prop in ret_props:
            db_prop = prop[1:]  # column name doesn't have _ prefix
            props[prop] = getattr(row, db_prop)
        return storage(**props)

    return Results(sa_ResultProxy=r, build_fn=build_fn)


if logging.getLogger('sqlalchemy').handlers:
    logging.getLogger('sqlalchemy').handlers[0].formatter = log_format

#inconsitencies:

#relationships assume their thing and data tables are in the same
#database. things don't make that assumption. in practice thing/data
#tables always go together.
#
#we create thing tables for a relationship's things that aren't on the
#same database as the relationship, although they're never used in
#practice. we could remove a healthy chunk of code if we removed that.