Open rive-n opened 2 years ago
I found a solution, but that's really strange one...
Before of starting pool: executor.start_polling(bot_dispatcher, skip_updates=True)
we need to configure Database object like this:
loop = get_event_loop()
db = Database(loop)
bot['db_pool'] = db
And Database
object:
class Database(object):
def __init__(self, loop):
if environ.get('DEBUG'):
self.host, self.port, self.database = '127.0.0.1', 5432, 'test'
else:
self.host, self.port, self.database = environ.get('PG_HOST', 'postgres'), environ.get('PG_PORT', 5432), environ.get("PG_DATABASE")
self.pool = loop.run_until_complete(create_pool(
user = environ.get('PG_USERNAME'),
password = environ.get('PG_PASSWORD'),
host = self.host, port = self.port,
database = self.database
))
This part is pretty strange for me:
loop.run_until_complete(create_pool(
user = environ.get('PG_USERNAME'),
password = environ.get('PG_PASSWORD'),
host = self.host, port = self.port,
database = self.database
))
Why we should create pool via loop object?