Skip to content

Commit

Permalink
Merge pull request #367 from Mause/bugfix/disable-comments
Browse files Browse the repository at this point in the history
fix: disable comments in dialect
  • Loading branch information
kodiakhq[bot] authored Aug 12, 2022
2 parents 8165aad + b69110b commit 55fc337
Showing 1 changed file with 2 additions and 40 deletions.
42 changes: 2 additions & 40 deletions duckdb_engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import warnings
from typing import TYPE_CHECKING, Any, Dict, List, Tuple, Type
from typing import Any, Dict, List, Tuple, Type

import duckdb
from sqlalchemy import pool
Expand All @@ -11,9 +10,6 @@

__version__ = "0.3.3"

if TYPE_CHECKING:
from sqlalchemy.sql.ddl import ExecutableDDLElement # type: ignore


class DBAPI:
paramstyle = duckdb.paramstyle
Expand Down Expand Up @@ -112,35 +108,13 @@ class DuckDBEngineWarning(Warning):
pass


class DuckDBEngineCommentWarning(DuckDBEngineWarning):
pass


def remove_comments(ddl: "ExecutableDDLElement") -> None:
# TODO: swap these attribute checks for type checks
if hasattr(ddl, "element"):
remove_comments(ddl.element)
elif hasattr(ddl, "elements"):
for el in ddl.elements:
remove_comments(el)
elif hasattr(ddl, "columns"):
for col in ddl.columns:
remove_comments(col)

if hasattr(ddl, "comment") and ddl.comment:
ddl.comment = None
warnings.warn(
"Stripping a comment, as duckdb does not support them",
category=DuckDBEngineCommentWarning,
)


class Dialect(postgres_dialect):
name = "duckdb"
driver = "duckdb_engine"
_has_events = False
identifier_preparer = None
supports_statement_cache = False
supports_comments = False
supports_sane_rowcount = False
inspector = DuckDBInspector
# colspecs TODO: remap types to duckdb types
Expand All @@ -166,18 +140,6 @@ def connect(
def on_connect(self) -> None:
pass

def ddl_compiler(
self,
dialect: str,
ddl: "ExecutableDDLElement",
**kwargs: Any,
) -> postgres_dialect.ddl_compiler:
# TODO: enforce no `serial` type

remove_comments(ddl)

return postgres_dialect.ddl_compiler(dialect, ddl, **kwargs)

def do_execute(
self,
cursor: ConnectionWrapper,
Expand Down

0 comments on commit 55fc337

Please sign in to comment.