|
3 | 3 | from typing import TYPE_CHECKING, Callable, NamedTuple
|
4 | 4 |
|
5 | 5 | import duckdb
|
6 |
| -import pandas as pd |
7 | 6 | import shapely.geometry
|
8 | 7 |
|
9 | 8 | from .data_types.camera_key import CameraKey
|
@@ -103,10 +102,10 @@ class Database:
|
103 | 102 |
|
104 | 103 | def __init__(self, connection: "duckdb.DuckDBPyConnection"):
|
105 | 104 | self.connection = connection
|
| 105 | + self.connection.install_extension("spatial") |
| 106 | + self.connection.load_extension("spatial") |
106 | 107 | self.cursor = self.connection.cursor()
|
107 | 108 |
|
108 |
| - self.cursor.execute("INSTALL spatial;") |
109 |
| - self.cursor.execute("LOAD spatial;") |
110 | 109 | self.cursor.commit()
|
111 | 110 | self.connection.commit()
|
112 | 111 |
|
@@ -287,7 +286,8 @@ def insert_camera(self, camera: list[CameraConfig]):
|
287 | 286 | cursor = self.connection.cursor()
|
288 | 287 | cursor.executemany(
|
289 | 288 | "INSERT INTO Camera VALUES "
|
290 |
| - "(?, ?, ?, ?, ST_GeomFromWKB(?), ?, ?, ST_GeomFromWKB(?), ?, ?, ?, ?)", |
| 289 | + "(?, ?, ?, ?, ST_GeomFromWKB(?), ?," |
| 290 | + " ?, ST_GeomFromWKB(?), ?, ?, ?, ?)", |
291 | 291 | map(_config, camera),
|
292 | 292 | )
|
293 | 293 |
|
@@ -333,12 +333,9 @@ def predicate(self, predicate: "PredicateNode", temporal: bool = True):
|
333 | 333 | for frame_number, camera_id, filename, *item_ids in self.execute(sql_str)
|
334 | 334 | ]
|
335 | 335 |
|
336 |
| - def sql(self, query: str) -> pd.DataFrame: |
337 |
| - results, cursor = self.execute_and_cursor(query) |
338 |
| - description = cursor.description |
339 |
| - assert description is not None |
340 |
| - cursor.close() |
341 |
| - return pd.DataFrame(results, columns=[d.name for d in description]) |
| 336 | + def sql(self, query: str) -> duckdb.DuckDBPyRelation: |
| 337 | + with self.connection.cursor() as cursor: |
| 338 | + return cursor.sql(query) |
342 | 339 |
|
343 | 340 |
|
344 | 341 | def _join_table(temporal: bool):
|
|
0 commit comments