35 lines
872 B
Python
35 lines
872 B
Python
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.models.imported_part_config import ImportedPartConfig
|
|
|
|
_SINGLETON_ID = 1
|
|
|
|
|
|
async def get(db: AsyncSession) -> ImportedPartConfig | None:
|
|
return await db.get(ImportedPartConfig, _SINGLETON_ID)
|
|
|
|
|
|
async def upsert(
|
|
db: AsyncSession,
|
|
*,
|
|
odata_url: str | None,
|
|
username: str | None,
|
|
password: str | None,
|
|
) -> ImportedPartConfig:
|
|
config = await db.get(ImportedPartConfig, _SINGLETON_ID)
|
|
if config is None:
|
|
config = ImportedPartConfig(
|
|
id=_SINGLETON_ID,
|
|
odata_url=odata_url,
|
|
username=username,
|
|
password=password,
|
|
)
|
|
db.add(config)
|
|
else:
|
|
config.odata_url = odata_url
|
|
config.username = username
|
|
config.password = password
|
|
await db.commit()
|
|
await db.refresh(config)
|
|
return config
|