Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- import asyncpg
- class Data:
- def __init__(self, query):
- self.query = query
- async def connect(self):
- conn = await asyncpg.connect(host='ip', port=port,
- user='user', password='password',
- database='db', timeout=20)
- result = await conn.fetch(self.query)
- await conn.close()
- return result
- def get_data(self):
- expect = asyncio.get_event_loop().run_until_complete(self.connect())
- data = []
- for ex in expect:
- data.append(dict(ex))
- return data # [{'first_1':"value",'first_2':"value"},{'second_1':"value",'second_2':"value"},]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement