def query_all(self, limit=None, order_by=None, include_extras=False, _log=False, **kwargs): #TODO: Does kwargs.keys() and kwargs.values() return items in the same order? where_clause = limit_clause = order_clause = '' values = [] if kwargs is not None and len(kwargs.keys()) > 0: where_parts = [] for key, value in kwargs.items(): where_part, use_value = self.get_where_part(key, value) where_parts.append(where_part) if use_value: values.append(value) where_clause = ' where ' + ' and '.join(where_parts) if limit is not None: limit_clause = ' limit {0} '.format(limit) if order_by is not None: order_clause = ' order by {0} '.format( order_by ) if not order_by.strip().startswith('order') else order_by query = 'select * from `{0}` {1} {2} {3} '.format( self._table_name, where_clause, order_clause, limit_clause) if _log: print query pprint(kwargs) rows = birdsql._get_db().fetch_all(query, tuple(values)) if _log: print 'Total rows returned:', len(rows) return self._create_objects(rows, include_extras)
def _create_objects(self, rows, include_extras=False): if rows is None or len(rows) == 0: return None else: return [ birdsql._get_db().get_generic(self.__class__(), row, include_extras) for row in rows ]
def query_all(self, limit=None, order_by=None, include_extras=False, _log=False, **kwargs): #TODO: Does kwargs.keys() and kwargs.values() return items in the same order? where_clause = limit_clause = order_clause = '' values = [] if kwargs is not None and len(kwargs.keys()) > 0: where_parts = [] for key, value in kwargs.items(): where_part, use_value = self.get_where_part(key, value) where_parts.append(where_part) if use_value: values.append(value) where_clause = ' where ' + ' and '.join(where_parts) if limit is not None: limit_clause = ' limit {0} '.format(limit) if order_by is not None: order_clause = ' order by {0} '.format(order_by) if not order_by.strip().startswith('order') else order_by query = 'select * from `{0}` {1} {2} {3} '.format(self._table_name, where_clause, order_clause, limit_clause) if _log: print query pprint(kwargs) rows = birdsql._get_db().fetch_all(query, tuple(values)) if _log: print 'Total rows returned:', len(rows) return self._create_objects(rows, include_extras)
def update_full(self): return birdsql._get_db().update_generic_full(self)
def update(self, what_list=None): return birdsql._get_db().update_generic(self, what_list)
def insert(self, replace_into=False): """ Insert this item into the database, optionally "REPLACE INTO" """ return birdsql._get_db().insert_generic(self, replace_into=replace_into)
def insert_or_update(self): return birdsql._get_db().insert_or_update_generic(self)
def _create_object(self, row, include_extras=False): return birdsql._get_db().get_generic(self, row, include_extras)
def raw_query_all(self, query, values, include_extras=False): rows = birdsql._get_db().fetch_all(query, values) return self._create_objects(rows, include_extras)
def delete(self): return birdsql._get_db().delete_generic(self)
def raw_query_one(self, query, values, include_extras=False): row = birdsql._get_db().fetch_one(query, values) return self._create_object(row, include_extras)