Given dictionaries of tables and view-queries, return a dictionary
    of all the rest of the queries I need.
775033
def queries(table):
    
    def update_where(updcols, wherecols):
        """Return an ``UPDATE`` statement that updates the columns ``updcols``
        when the ``wherecols`` match. Every column has a bound parameter of
        the same name.

        updcols are strings, wherecols are column objects

        """
        vmap = OrderedDict()
        for col in updcols:
            vmap[col] = bindparam(col)
        wheres = [
            c == bindparam(c.name) for c in wherecols
        ]
        tab = wherecols[0].table
        return tab.update().values(**vmap).where(and_(*wheres))

    r = allegedb.alchemy.queries_for_table_dict(table)

    rulebooks = table['rulebooks']
    r['rulebooks_update'] = update_where(['rules'], [rulebooks.c.rulebook, rulebooks.c.branch, rulebooks.c.turn, rulebooks.c.tick])

    for t in table.values():
        key = list(t.primary_key)
        if 'branch' in t.columns and 'turn' in t.columns and 'tick' in t.columns:
            branch = t.columns['branch']
            turn = t.columns['turn']
            tick = t.columns['tick']
            if branch in key and turn in key and tick in key:
                key = [branch, turn, tick]
        r[t.name + '_dump'] = select(list(t.c.values())).order_by(*key)
        r[t.name + '_insert'] = t.insert().values(tuple(bindparam(cname) for cname in t.c.keys()))
        r[t.name + '_count'] = select([func.COUNT('*')]).select_from(t)

    r['del_char_things'] = table['things'].delete().where(
        table['things'].c.character == bindparam('character')
    )

    r['del_char_avatars'] = table['avatars'].delete().where(
        table['avatars'].c.character_graph == bindparam('character')
    )
    things = table['things']
    r['del_things_after'] = things.delete().where(and_(
        things.c.character == bindparam('character'),
        things.c.thing == bindparam('thing'),
        things.c.branch == bindparam('branch'),
        or_(
            things.c.turn > bindparam('turn'),
            and_(
                things.c.turn == bindparam('turn'),
                things.c.tick >= bindparam('tick')
            )
        )
    ))
    avatars = table['avatars']
    r['del_avatars_after'] = avatars.delete().where(and_(
        avatars.c.character_graph == bindparam('character'),
        avatars.c.avatar_graph == bindparam('graph'),
        avatars.c.avatar_node == bindparam('avatar'),
        avatars.c.branch == bindparam('branch'),
        or_(
            avatars.c.turn > bindparam('turn'),
            and_(
                avatars.c.turn == bindparam('turn'),
                avatars.c.tick >= bindparam('tick')
            )
        )
    ))

    branches = table['branches']

    r['branch_children'] = select(
        [branches.c.branch]
    ).where(
        branches.c.parent == bindparam('branch')
    )

    tc = table['turns_completed']
    r['turns_completed_update'] = update_where(['turn'], [tc.c.branch])

    return r
66363
def asDictionary(self):
        
        return {
            "type": "joinTable",
            "leftTableSource": self._leftTableSource,
            "rightTableSource": self._rightTableSource,
            "leftTableKey": self._leftTableKey,
            "rightTableKey": self._rightTableKey,
            "joinType": self._joinType
        }
589324
def dictfetchall(cursor):
    
    desc = cursor.description
    return [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()]
1018244
def _fetchall(self, query, vars, limit=None, offset=0):
        
        if limit is None:
            limit = current_app.config['DEFAULT_PAGE_SIZE']
        query += ' LIMIT %s OFFSET %s''' % (limit, offset)
        cursor = self.get_db().cursor()
        self._log(cursor, query, vars)
        cursor.execute(query, vars)
        return cursor.fetchall()
787652
def tables(self):
        
        datasets = DatasetManager(self.auth_client).filter(
            show_table_size_and_row_count='false',
            show_table='false',
            show_stats='false',
            show_likes='false',
            show_liked='false',
            show_permission='false',
            show_uses_builder_features='false',
            show_synchronization='false',
            load_totals='false')
        return [Table.from_dataset(d) for d in datasets]
572337
def _build_dictionary(self, results):
        
        foreign = self._first_key

        dictionary = {}

        for result in results:
            key = getattr(result, foreign)
            if key not in dictionary:
                dictionary[key] = []

            dictionary[key].append(result)

        return dictionary
193056
def tables(self):
        
        from ambry.orm import Table
        from sqlalchemy.orm import lazyload

        return (self.dataset.session.query(Table)
                .filter(Table.d_vid == self.dataset.vid)
                .options(lazyload('*'))
                .all())
1089431
def get_indexes(self):
        
        ret = {}
        for index in self.iter_query_indexes():
            ret[index.name] = index
        return ret
630142
def find_all(self, *queries):
        
        return self.select(*queries, deep=True, roots=False)
1122837
def get_tables_for_bind(self, bind=None):
        """"""
        result = []
        for table in itervalues(self.Model.metadata.tables):
            if table.info.get('bind_key') == bind:
                result.append(table)
        return result
621111
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self,
                   'counterexamples') and self.counterexamples is not None:
            _dict['counterexamples'] = [
                x._to_dict() for x in self.counterexamples
            ]
        if hasattr(self, 'pagination') and self.pagination is not None:
            _dict['pagination'] = self.pagination._to_dict()
        return _dict
90456
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'environment_id') and self.environment_id is not None:
            _dict['environment_id'] = self.environment_id
        if hasattr(self, 'collection_id') and self.collection_id is not None:
            _dict['collection_id'] = self.collection_id
        if hasattr(self, 'queries') and self.queries is not None:
            _dict['queries'] = [x._to_dict() for x in self.queries]
        return _dict
1234719
def list_tables(self):
        '''
        
        '''
        if not self._tables:
            for table_name in os.listdir(self.db_path):
                self._tables[table_name] = self._load_table(table_name)

        return self._tables.keys()
307834
def mk_dict(results,description):
    """"""
    
    rows=[]
    for row in results:
        row_dict={}
        for idx in range(len(row)):
            col=description[idx][0]
            row_dict[col]=row[idx]
        rows.append(row_dict)
    return rows
721120
def queries(self):
        
        if self._queries is None:
            self._queries = QueryList(self._version, assistant_sid=self._solution['sid'], )
        return self._queries
550950
def tablesAndViews(self):
      """"""
      result = self.execute(
        u'SELECT name,type FROM sqlite_master WHERE type in ("table", "view")',
        commit=False)
      return ((row['name'],row['type']) for row in result)
514999
def getAll(self):
        
        objs = []
        for obj in self.model.db:
            objs.append(self._cast_model(obj))

        return objs