From 1d7150a0f229806afc6a22e6e982d99a2e00f400 Mon Sep 17 00:00:00 2001 From: "Chanwut (Mick) Kittivorawong" Date: Mon, 3 Mar 2025 06:38:25 +0000 Subject: [PATCH 1/2] fix database sql --- spatialyze/database.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/spatialyze/database.py b/spatialyze/database.py index 1bb69429..3867424a 100644 --- a/spatialyze/database.py +++ b/spatialyze/database.py @@ -103,10 +103,10 @@ class Database: def __init__(self, connection: "duckdb.DuckDBPyConnection"): self.connection = connection + self.connection.install_extension("spatial") + self.connection.load_extension("spatial") self.cursor = self.connection.cursor() - self.cursor.execute("INSTALL spatial;") - self.cursor.execute("LOAD spatial;") self.cursor.commit() self.connection.commit() @@ -287,7 +287,8 @@ def insert_camera(self, camera: list[CameraConfig]): cursor = self.connection.cursor() cursor.executemany( "INSERT INTO Camera VALUES " - "(?, ?, ?, ?, ST_GeomFromWKB(?), ?, ?, ST_GeomFromWKB(?), ?, ?, ?, ?)", + "(?, ?, ?, ?, ST_GeomFromWKB(?), ?," + " ?, ST_GeomFromWKB(?), ?, ?, ?, ?)", map(_config, camera), ) @@ -333,12 +334,9 @@ def predicate(self, predicate: "PredicateNode", temporal: bool = True): for frame_number, camera_id, filename, *item_ids in self.execute(sql_str) ] - def sql(self, query: str) -> pd.DataFrame: - results, cursor = self.execute_and_cursor(query) - description = cursor.description - assert description is not None - cursor.close() - return pd.DataFrame(results, columns=[d.name for d in description]) + def sql(self, query: str) -> duckdb.DuckDBPyRelation: + with self.connection.cursor() as cursor: + return cursor.sql(query) def _join_table(temporal: bool): From 6b59fb3a270e708f254504081e34138f1fee3b98 Mon Sep 17 00:00:00 2001 From: Github Actions Bot Date: Mon, 3 Mar 2025 06:39:21 +0000 Subject: [PATCH 2/2] style: [CI] format --- spatialyze/database.py | 1 - 1 file changed, 1 deletion(-) diff --git a/spatialyze/database.py b/spatialyze/database.py index 3867424a..a1f1aea9 100644 --- a/spatialyze/database.py +++ b/spatialyze/database.py @@ -3,7 +3,6 @@ from typing import TYPE_CHECKING, Callable, NamedTuple import duckdb -import pandas as pd import shapely.geometry from .data_types.camera_key import CameraKey