Skip to content

Instantly share code, notes, and snippets.

@justnoise
Created July 8, 2016 06:33
Show Gist options
  • Select an option

  • Save justnoise/d8720e566c841a2bcbd12c7744de6dcc to your computer and use it in GitHub Desktop.

Select an option

Save justnoise/d8720e566c841a2bcbd12c7744de6dcc to your computer and use it in GitHub Desktop.
Simple demonstration of streaming queries from mysql
import MySQLdb
import logging
log = logging.getLogger(__name__)
class StreamingMysqlClient(object):
def __init__(self, host, user, password, dbname):
self.conn = MySQLdb.connect(host, user, password, dbname)
def stream_query(self, query):
cursor = self.conn.cursor(MySQLdb.cursors.SSCursor)
cursor.execute(query)
row = cursor.fetchone()
while row is not None:
yield row
row = cursor.fetchone()
def main():
db = StreamingMysqlClient('localhost', 'justnoise', 'ILikeToParty', 'party_times')
results = db.stream_query('select * from shindigs')
for values in results:
print values
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment