mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-12-19 19:13:02 +08:00
fix: use ".rowcount" instead of ".returning" on SQLite
This commit is contained in:
parent
6cfa94ec58
commit
a7f2546558
@ -513,14 +513,20 @@ async def ingest_fs_asset(
|
|||||||
"created_at": now,
|
"created_at": now,
|
||||||
}
|
}
|
||||||
if dialect == "sqlite":
|
if dialect == "sqlite":
|
||||||
ins = (
|
res = await session.execute(
|
||||||
d_sqlite.insert(Asset)
|
d_sqlite.insert(Asset)
|
||||||
.values(**vals)
|
.values(**vals)
|
||||||
.on_conflict_do_nothing(index_elements=[Asset.hash])
|
.on_conflict_do_nothing(index_elements=[Asset.hash])
|
||||||
.returning(Asset.id)
|
|
||||||
)
|
)
|
||||||
|
if int(res.rowcount or 0) > 0:
|
||||||
|
out["asset_created"] = True
|
||||||
|
asset = (
|
||||||
|
await session.execute(
|
||||||
|
select(Asset).where(Asset.hash == asset_hash).limit(1)
|
||||||
|
)
|
||||||
|
).scalars().first()
|
||||||
elif dialect == "postgresql":
|
elif dialect == "postgresql":
|
||||||
ins = (
|
res = await session.execute(
|
||||||
d_pg.insert(Asset)
|
d_pg.insert(Asset)
|
||||||
.values(**vals)
|
.values(**vals)
|
||||||
.on_conflict_do_nothing(
|
.on_conflict_do_nothing(
|
||||||
@ -529,22 +535,18 @@ async def ingest_fs_asset(
|
|||||||
)
|
)
|
||||||
.returning(Asset.id)
|
.returning(Asset.id)
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
raise NotImplementedError(f"Unsupported database dialect: {dialect}")
|
|
||||||
res = await session.execute(ins)
|
|
||||||
inserted_id = res.scalar_one_or_none()
|
inserted_id = res.scalar_one_or_none()
|
||||||
asset = (
|
|
||||||
await session.execute(select(Asset).where(Asset.hash == asset_hash).limit(1))
|
|
||||||
).scalars().first()
|
|
||||||
if not asset:
|
|
||||||
raise RuntimeError("Asset row not found after upsert.")
|
|
||||||
if inserted_id:
|
if inserted_id:
|
||||||
out["asset_created"] = True
|
out["asset_created"] = True
|
||||||
asset = await session.get(Asset, inserted_id)
|
asset = await session.get(Asset, inserted_id)
|
||||||
else:
|
else:
|
||||||
asset = (
|
asset = (
|
||||||
await session.execute(select(Asset).where(Asset.hash == asset_hash).limit(1))
|
await session.execute(
|
||||||
|
select(Asset).where(Asset.hash == asset_hash).limit(1)
|
||||||
|
)
|
||||||
).scalars().first()
|
).scalars().first()
|
||||||
|
else:
|
||||||
|
raise NotImplementedError(f"Unsupported database dialect: {dialect}")
|
||||||
if not asset:
|
if not asset:
|
||||||
raise RuntimeError("Asset row not found after upsert.")
|
raise RuntimeError("Asset row not found after upsert.")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -377,17 +377,20 @@ async def touch_asset_info_by_id(
|
|||||||
stmt = stmt.where(
|
stmt = stmt.where(
|
||||||
sa.or_(AssetInfo.last_access_time.is_(None), AssetInfo.last_access_time < ts)
|
sa.or_(AssetInfo.last_access_time.is_(None), AssetInfo.last_access_time < ts)
|
||||||
)
|
)
|
||||||
stmt = stmt.values(last_access_time=ts).returning(AssetInfo.id)
|
stmt = stmt.values(last_access_time=ts)
|
||||||
return (await session.execute(stmt)).scalar_one_or_none() is not None
|
if session.bind.dialect.name == "postgresql":
|
||||||
|
return (await session.execute(stmt.returning(AssetInfo.id))).scalar_one_or_none() is not None
|
||||||
|
return int((await session.execute(stmt)).rowcount or 0) > 0
|
||||||
|
|
||||||
|
|
||||||
async def delete_asset_info_by_id(session: AsyncSession, *, asset_info_id: str, owner_id: str) -> bool:
|
async def delete_asset_info_by_id(session: AsyncSession, *, asset_info_id: str, owner_id: str) -> bool:
|
||||||
return (
|
stmt = sa.delete(AssetInfo).where(
|
||||||
await session.execute(delete(AssetInfo).where(
|
|
||||||
AssetInfo.id == asset_info_id,
|
AssetInfo.id == asset_info_id,
|
||||||
visible_owner_clause(owner_id),
|
visible_owner_clause(owner_id),
|
||||||
).returning(AssetInfo.id))
|
)
|
||||||
).scalar_one_or_none() is not None
|
if session.bind.dialect.name == "postgresql":
|
||||||
|
return (await session.execute(stmt.returning(AssetInfo.id))).scalar_one_or_none() is not None
|
||||||
|
return int((await session.execute(stmt)).rowcount or 0) > 0
|
||||||
|
|
||||||
|
|
||||||
async def add_tags_to_asset_info(
|
async def add_tags_to_asset_info(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user