Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import asyncio
  2.  
  3. import asyncpg
  4.  
  5.  
  6. class Data:
  7. def __init__(self, query):
  8. self.query = query
  9.  
  10. async def connect(self):
  11. conn = await asyncpg.connect(host='ip', port=port,
  12. user='user', password='password',
  13. database='db', timeout=20)
  14. result = await conn.fetch(self.query)
  15. await conn.close()
  16. return result
  17.  
  18. def get_data(self):
  19. expect = asyncio.get_event_loop().run_until_complete(self.connect())
  20. data = []
  21. for ex in expect:
  22. data.append(dict(ex))
  23. return data # [{'first_1':"value",'first_2':"value"},{'second_1':"value",'second_2':"value"},]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement