You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					31 lines
				
				1.2 KiB
			
		
		
			
		
	
	
					31 lines
				
				1.2 KiB
			| 
											1 year ago
										 | from sqlalchemy.ext.asyncio import create_async_engine | ||
|  | from sqlalchemy.ext.asyncio import async_sessionmaker | ||
|  | from sqlalchemy.ext.asyncio import AsyncAttrs | ||
|  | from sqlalchemy.orm import DeclarativeBase | ||
| 
											2 years ago
										 | from urllib.parse import quote_plus | ||
|  | from config.env import DataBaseConfig | ||
|  | 
 | ||
| 
											1 year ago
										 | ASYNC_SQLALCHEMY_DATABASE_URL = ( | ||
|  |     f'mysql+asyncmy://{DataBaseConfig.db_username}:{quote_plus(DataBaseConfig.db_password)}@' | ||
|  |     f'{DataBaseConfig.db_host}:{DataBaseConfig.db_port}/{DataBaseConfig.db_database}' | ||
|  | ) | ||
| 
											1 year ago
										 | if DataBaseConfig.db_type == 'postgresql': | ||
|  |     ASYNC_SQLALCHEMY_DATABASE_URL = ( | ||
|  |         f'postgresql+asyncpg://{DataBaseConfig.db_username}:{quote_plus(DataBaseConfig.db_password)}@' | ||
|  |         f'{DataBaseConfig.db_host}:{DataBaseConfig.db_port}/{DataBaseConfig.db_database}' | ||
|  |     ) | ||
| 
											2 years ago
										 | 
 | ||
| 
											1 year ago
										 | async_engine = create_async_engine( | ||
|  |     ASYNC_SQLALCHEMY_DATABASE_URL, | ||
| 
											2 years ago
										 |     echo=DataBaseConfig.db_echo, | ||
|  |     max_overflow=DataBaseConfig.db_max_overflow, | ||
|  |     pool_size=DataBaseConfig.db_pool_size, | ||
|  |     pool_recycle=DataBaseConfig.db_pool_recycle, | ||
| 
											1 year ago
										 |     pool_timeout=DataBaseConfig.db_pool_timeout, | ||
| 
											2 years ago
										 | ) | ||
| 
											1 year ago
										 | AsyncSessionLocal = async_sessionmaker(autocommit=False, autoflush=False, bind=async_engine) | ||
|  | 
 | ||
|  | 
 | ||
|  | class Base(AsyncAttrs, DeclarativeBase): | ||
|  |     pass |