Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions datamind/capabilities/db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,20 @@ def _before_query(self, conn: Any) -> None: # noqa: D401
def _quote_ident(self, name: str) -> str:
"""Default identifier quoting; dialects override for back-ticks etc."""
return '"' + name.replace('"', '""') + '"'

async def count_by_source(
self,
engine: Engine,
table: str,
*,
source_file: str,
source_column: str = "_source_file",
) -> int:
q = self._quote_ident
sql = f"SELECT COUNT(*) FROM {q(table)} WHERE {q(source_column)} = :sf"

def _run() -> int:
with engine.connect() as conn:
return int(conn.execute(text(sql), {"sf": source_file}).scalar() or 0)

return await asyncio.to_thread(_run)
Loading