mirror of
				https://github.com/ijaric/voice_assistant.git
				synced 2025-10-31 01:33:25 +00:00 
			
		
		
		
	feat: extened settings
This commit is contained in:
		
							parent
							
								
									31951ca824
								
							
						
					
					
						commit
						8bc6972ca2
					
				|  | @ -14,6 +14,13 @@ class DBSettings(pydantic_settings.BaseSettings): | |||
|     user: str | ||||
|     password: pydantic.SecretStr | ||||
| 
 | ||||
|     pool_size: int | ||||
|     pool_pre_ping: bool | ||||
|     echo: bool | ||||
|     auto_commit: bool | ||||
|     auto_flush: bool | ||||
|     expire_on_commit: bool | ||||
| 
 | ||||
|     @property | ||||
|     def dsn(self) -> str: | ||||
|         """Get database DSN.""" | ||||
|  | @ -36,3 +43,10 @@ class PostgresSettings(DBSettings): | |||
|     password: pydantic.SecretStr = pydantic.Field( | ||||
|         default=..., validation_alias=pydantic.AliasChoices("password", "postgres_password") | ||||
|     ) | ||||
| 
 | ||||
|     pool_size: int = 50 | ||||
|     pool_pre_ping: bool = True | ||||
|     echo: bool = False | ||||
|     auto_commit: bool = False | ||||
|     auto_flush: bool = False | ||||
|     expire_on_commit: bool = False | ||||
|  |  | |||
|  | @ -9,10 +9,19 @@ class AsyncDB: | |||
|     """Async DB connection.""" | ||||
| 
 | ||||
|     def __init__(self, settings: app_settings.Settings): | ||||
|         self.database_dsn = settings.db.dsn | ||||
|         self.engine = sa_asyncio.create_async_engine(self.database_dsn, echo=settings.project.debug, future=True) | ||||
|         self.engine = sa_asyncio.create_async_engine( | ||||
|             url=settings.db.dsn, | ||||
|             pool_size=settings.db.pool_size, | ||||
|             pool_pre_ping=settings.db.pool_pre_ping, | ||||
|             echo=settings.db.echo, | ||||
|             future=True, | ||||
|         ) | ||||
|         self.async_session = sa_asyncio.async_sessionmaker( | ||||
|             self.engine, class_=sa_asyncio.AsyncSession, expire_on_commit=False | ||||
|             bind=self.engine, | ||||
|             autocommit=settings.db.auto_commit, | ||||
|             autoflush=settings.db.auto_flush, | ||||
|             expire_on_commit=settings.db.expire_on_commit, | ||||
|             class_=sa_asyncio.AsyncSession, | ||||
|         ) | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user