mirror of
				https://github.com/ijaric/voice_assistant.git
				synced 2025-10-31 01:33:25 +00:00 
			
		
		
		
	fix: provide db settings
This commit is contained in:
		
							parent
							
								
									8bc6972ca2
								
							
						
					
					
						commit
						bee0048a61
					
				|  | @ -8,7 +8,7 @@ import lib.app.split_settings as app_split_settings | ||||||
| 
 | 
 | ||||||
| class Settings(pydantic_settings.BaseSettings): | class Settings(pydantic_settings.BaseSettings): | ||||||
|     api: app_split_settings.ApiSettings = pydantic.Field(default_factory=lambda: app_split_settings.ApiSettings()) |     api: app_split_settings.ApiSettings = pydantic.Field(default_factory=lambda: app_split_settings.ApiSettings()) | ||||||
|     db: app_split_settings.PostgresSettings = pydantic.Field( |     postgres: app_split_settings.PostgresSettings = pydantic.Field( | ||||||
|         default_factory=lambda: app_split_settings.PostgresSettings() |         default_factory=lambda: app_split_settings.PostgresSettings() | ||||||
|     ) |     ) | ||||||
|     logger: app_split_settings.LoggingSettings = pydantic.Field( |     logger: app_split_settings.LoggingSettings = pydantic.Field( | ||||||
|  |  | ||||||
|  | @ -2,30 +2,32 @@ import typing | ||||||
| 
 | 
 | ||||||
| import sqlalchemy.ext.asyncio as sa_asyncio | import sqlalchemy.ext.asyncio as sa_asyncio | ||||||
| 
 | 
 | ||||||
| import lib.app.settings as app_settings | import lib.app.split_settings as app_split_settings | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class AsyncDB: | class AsyncDB: | ||||||
|     """Async DB connection.""" |     """Async DB connection.""" | ||||||
| 
 | 
 | ||||||
|     def __init__(self, settings: app_settings.Settings): |     def __init__(self, settings: app_split_settings.DBSettings): | ||||||
|         self.engine = sa_asyncio.create_async_engine( |         self.engine = sa_asyncio.create_async_engine( | ||||||
|             url=settings.db.dsn, |             url=settings.dsn, | ||||||
|             pool_size=settings.db.pool_size, |             pool_size=settings.pool_size, | ||||||
|             pool_pre_ping=settings.db.pool_pre_ping, |             pool_pre_ping=settings.pool_pre_ping, | ||||||
|             echo=settings.db.echo, |             echo=settings.echo, | ||||||
|             future=True, |             future=True, | ||||||
|         ) |         ) | ||||||
|         self.async_session = sa_asyncio.async_sessionmaker( |         self.async_session = sa_asyncio.async_sessionmaker( | ||||||
|             bind=self.engine, |             bind=self.engine, | ||||||
|             autocommit=settings.db.auto_commit, |             autocommit=settings.auto_commit, | ||||||
|             autoflush=settings.db.auto_flush, |             autoflush=settings.auto_flush, | ||||||
|             expire_on_commit=settings.db.expire_on_commit, |             expire_on_commit=settings.expire_on_commit, | ||||||
|             class_=sa_asyncio.AsyncSession, |             class_=sa_asyncio.AsyncSession, | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| async def get_session(settings: app_settings.Settings) -> typing.AsyncGenerator[sa_asyncio.AsyncSession, typing.Any]: | async def get_session( | ||||||
|  |     settings: app_split_settings.DBSettings, | ||||||
|  | ) -> typing.AsyncGenerator[sa_asyncio.AsyncSession, typing.Any]: | ||||||
|     db = AsyncDB(settings) |     db = AsyncDB(settings) | ||||||
|     async with db.async_session() as session: |     async with db.async_session() as session: | ||||||
|         try: |         try: | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user