|
18 | 18 | import asyncpg |
19 | 19 | from typing import Awaitable |
20 | 20 |
|
21 | | -DB_SCHEMA = os.environ.get('DATABASE_SCHEMA', None) |
| 21 | +DB_SCHEMA = os.environ.get("DATABASE_SCHEMA", None) |
22 | 22 |
|
23 | 23 |
|
24 | 24 | async def init_db_pool() -> Awaitable: |
25 | 25 | """Create a connection pool. |
26 | 26 |
|
27 | 27 | As we will have frequent requests to the database it is recommended to create a connection pool. |
28 | 28 | """ |
29 | | - return await asyncpg.create_pool(host=os.environ.get('DATABASE_URL', 'localhost'), |
30 | | - port=os.environ.get('DATABASE_PORT', '5432'), |
31 | | - user=os.environ.get('DATABASE_USER', 'beacon'), |
32 | | - password=os.environ.get('DATABASE_PASSWORD', 'beacon'), |
33 | | - database=os.environ.get('DATABASE_NAME', 'beacondb'), |
34 | | - # Multiple schemas can be used, and they need to be comma separated |
35 | | - server_settings={'search_path': DB_SCHEMA if DB_SCHEMA else 'public'}, |
36 | | - # initializing with 0 connections allows the web server to |
37 | | - # start and also continue to live |
38 | | - min_size=0, |
39 | | - # for now limiting the number of connections in the pool |
40 | | - max_size=20, |
41 | | - max_queries=50000, |
42 | | - timeout=120, |
43 | | - command_timeout=180, |
44 | | - max_cached_statement_lifetime=0, |
45 | | - max_inactive_connection_lifetime=180) |
| 29 | + return await asyncpg.create_pool( |
| 30 | + host=os.environ.get("DATABASE_URL", "localhost"), |
| 31 | + port=os.environ.get("DATABASE_PORT", "5432"), |
| 32 | + user=os.environ.get("DATABASE_USER", "beacon"), |
| 33 | + password=os.environ.get("DATABASE_PASSWORD", "beacon"), |
| 34 | + database=os.environ.get("DATABASE_NAME", "beacondb"), |
| 35 | + # Multiple schemas can be used, and they need to be comma separated |
| 36 | + server_settings={"search_path": DB_SCHEMA if DB_SCHEMA else "public"}, |
| 37 | + # initializing with 0 connections allows the web server to |
| 38 | + # start and also continue to live |
| 39 | + min_size=0, |
| 40 | + # for now limiting the number of connections in the pool |
| 41 | + max_size=20, |
| 42 | + max_queries=50000, |
| 43 | + timeout=120, |
| 44 | + command_timeout=180, |
| 45 | + max_cached_statement_lifetime=0, |
| 46 | + max_inactive_connection_lifetime=180, |
| 47 | + ) |
0 commit comments