Skip to content

Commit ea3bea3

Browse files
author
meomeocoj
committed
feat: fix type
1 parent 9dea049 commit ea3bea3

2 files changed

Lines changed: 31 additions & 26 deletions

File tree

‎duckdb_engine/__init__.py‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
import warnings
3+
from collections.abc import Hashable
34
from functools import lru_cache
45
from typing import (
56
TYPE_CHECKING,
@@ -175,6 +176,26 @@ def fetchmany(self, size: Optional[int] = None) -> List:
175176
else:
176177
return self.__c.fetchmany(size)
177178

179+
@property
180+
def description(self) -> Optional[List[Tuple[Any, ...]]]:
181+
description = self.__c.description
182+
if description is None:
183+
return None
184+
185+
sanitized: List[Tuple[Any, ...]] = []
186+
for row in description:
187+
if len(row) <= 1:
188+
sanitized.append(tuple(row))
189+
continue
190+
191+
type_code = row[1]
192+
if isinstance(type_code, Hashable):
193+
sanitized.append(tuple(row))
194+
else:
195+
sanitized.append((row[0], str(type_code), *row[2:]))
196+
197+
return sanitized
198+
178199

179200
class DuckDBEngineWarning(Warning):
180201
pass
@@ -283,6 +304,7 @@ def type_descriptor(self, typeobj: Type[sqltypes.TypeEngine]) -> Any: # type: i
283304
return res
284305

285306
def connect(self, *cargs: Any, **cparams: Any) -> "Connection":
307+
print("duckdb version:", duckdb_version)
286308
core_keys = get_core_config()
287309
preload_extensions = cparams.pop("preload_extensions", [])
288310
config = dict(cparams.get("config", {}))
@@ -409,7 +431,7 @@ def get_schema_names(self, connection: "Connection", **kw: "Any"): # type: igno
409431
s = """
410432
SELECT database_name, schema_name AS nspname
411433
FROM duckdb_schemas()
412-
WHERE schema_name NOT LIKE 'pg\_%' ESCAPE '\'
434+
WHERE schema_name NOT LIKE 'pg\\_%' ESCAPE '\\'
413435
ORDER BY database_name, nspname
414436
"""
415437
rs = connection.execute(text(s))

‎duckdb_engine/tests/test_ducklake.py‎

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -192,38 +192,21 @@ def readonly_ducklake_engine(temp_dir: Path) -> Engine:
192192
)
193193
return readonly_engine
194194

195-
@pytest.fixture
196-
def postgres(temp_dir: Path) -> Engine:
195+
def test_postgres(temp_dir: Path) -> Engine:
197196
data_path = temp_dir / "data"
198197
data_path.mkdir()
199198
registry.register("duckdb", "duckdb_engine", "Dialect")
200-
catalog_path = temp_dir / "test_catalog.ducklake"
201199

202200
# First create some test data with a writable connection
203-
writable_engine = create_engine(
204-
f"ducklake:postgres:dbname=ducklake user=postgres password=FvTEBiSdLOlo host=15.235.225.242 port=5433",
201+
ducklake_engine = create_engine(
202+
f"duckdb:///ducklake:postgres:dbname=ducklake user=postgres password=FvTEBiSdLOlo host=15.235.225.242 port=5433",
205203
)
206-
with writable_engine.connect() as conn:
207-
conn.execute(
208-
text("""
209-
CREATE TABLE readonly_test (
210-
id INTEGER,
211-
name VARCHAR
212-
)
213-
""")
214-
)
215-
conn.execute(text("INSERT INTO readonly_test VALUES (1, 'existing_data')"))
204+
with ducklake_engine.connect() as conn:
205+
inspector = inspect(ducklake_engine)
206+
schemas = inspector.get_schema_names()
207+
print(f"Schemas: {schemas}")
216208

217-
# Return readonly engine
218-
readonly_engine = create_engine(
219-
f"duckdb:///ducklake:{catalog_path}",
220-
connect_args={
221-
"data_path": str(data_path),
222-
"alias": "test_readonly",
223-
"read_only": True,
224-
},
225-
)
226-
return readonly_engine
209+
return ducklake_engine
227210

228211

229212
def test_ducklake_readonly_prevents_writes(readonly_ducklake_engine: Engine) -> None:

0 commit comments

Comments
 (0)