add CSV format for importance import

This commit is contained in:
Sarah Hoffmann
2024-05-05 09:39:52 +02:00
parent 5c7073901e
commit 60b03d506f
6 changed files with 167 additions and 39 deletions

View File

@@ -92,6 +92,11 @@ class CopyBuffer:
return self
def size(self) -> int:
""" Return the number of bytes the buffer currently contains.
"""
return self.buffer.tell()
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
if self.buffer is not None:
self.buffer.close()
@@ -115,7 +120,10 @@ class CopyBuffer:
def copy_out(self, cur: Cursor, table: str, columns: Optional[Iterable[str]] = None) -> None:
""" Copy all collected data into the given table.
The buffer is empty and reusable after this operation.
"""
if self.buffer.tell() > 0:
self.buffer.seek(0)
cur.copy_from(self.buffer, table, columns=columns)
self.buffer = io.StringIO()