blob: a337a543532454288ded05e1a099f8dfcaa634c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
from __future__ import print_function, division, absolute_import
import sys
sys.path.append("../../..")
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
from sqlalchemy.orm import scoped_session, sessionmaker, relationship, backref
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.ext.declarative import declarative_base
import zach_settings as zs
Engine = sa.create_engine(zs.SQLALCHEMY_DATABASE_URI,
#encoding='utf-8',
#client_encoding='utf-8',
echo="debug",
)
Session = scoped_session(sessionmaker(bind=Engine)) #, extension=VersionedListener()))
#Xsession = Session()
Base = declarative_base(bind=Engine)
Metadata = sa.MetaData()
Metadata.bind = Engine
class ProbeSet(Base):
__tablename__ = 'ProbeSet'
__table_args__ = {'autoload': True}
def main():
for ps in page_query(Session.query(ProbeSet)): #all()
#for ps in probe_sets:
print("--->", ps)
def page_query(q):
"""http://stackoverflow.com/a/1217947/1175849"""
offset = 0
while True:
r = False
for elem in q.limit(1000).offset(offset):
r = True
yield elem
offset += 1000
if not r:
break
if __name__ == "__main__":
main()
|