Refactor to simplify
This commit is contained in:
parent
d3fe91bc73
commit
b723b7da7c
@ -59,8 +59,7 @@ class Database(object):
|
|||||||
return self.get_table(table_name)
|
return self.get_table(table_name)
|
||||||
|
|
||||||
def query(self, query):
|
def query(self, query):
|
||||||
for res in resultiter(self.engine.execute(query)):
|
return resultiter(self.engine.execute(query)):
|
||||||
yield res
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Database(%s)>' % self.url
|
return '<Database(%s)>' % self.url
|
||||||
|
|||||||
@ -4,7 +4,7 @@ from itertools import count
|
|||||||
from sqlalchemy.sql import and_, expression
|
from sqlalchemy.sql import and_, expression
|
||||||
from sqlalchemy.schema import Column, Index
|
from sqlalchemy.schema import Column, Index
|
||||||
|
|
||||||
from dataset.persistence.util import guess_type, resultiter
|
from dataset.persistence.util import guess_type
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -116,7 +116,7 @@ class Table(object):
|
|||||||
break
|
break
|
||||||
q = self.table.select(whereclause=args, limit=qlimit,
|
q = self.table.select(whereclause=args, limit=qlimit,
|
||||||
offset=qoffset, order_by=order_by)
|
offset=qoffset, order_by=order_by)
|
||||||
rows = list(resultiter(self.database.engine.execute(q)))
|
rows = list(self.database.query(q))
|
||||||
if not len(rows):
|
if not len(rows):
|
||||||
return
|
return
|
||||||
for row in rows:
|
for row in rows:
|
||||||
@ -134,7 +134,7 @@ class Table(object):
|
|||||||
q = expression.select(columns, distinct=True,
|
q = expression.select(columns, distinct=True,
|
||||||
whereclause=and_(*qargs),
|
whereclause=and_(*qargs),
|
||||||
order_by=[c.asc() for c in columns])
|
order_by=[c.asc() for c in columns])
|
||||||
return resultiter(self.database.engine.execute(q))
|
return self.database.query(q)
|
||||||
|
|
||||||
def all(self):
|
def all(self):
|
||||||
return self.find()
|
return self.find()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user