Skip to content

Commit

Permalink
fix: properly support UUID type
Browse files Browse the repository at this point in the history
Fixes #530
  • Loading branch information
Mause authored Mar 1, 2023
1 parent 42a0192 commit b138b85
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions duckdb_engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def execute(
else:
raise e

from sqlalchemy.dialects.postgresql import UUID

class DuckDBEngineWarning(Warning):
pass
Expand All @@ -160,6 +161,7 @@ class Dialect(PGDialect_psycopg2):
sqltypes.Numeric: sqltypes.Numeric,
sqltypes.Interval: sqltypes.Interval,
sqltypes.JSON: sqltypes.JSON,
UUID: UUID
},
)

Expand Down
22 changes: 22 additions & 0 deletions duckdb_engine/tests/test_datatypes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import Type

from uuid import uuid4
from pytest import mark
from sqlalchemy import Column, Integer
from sqlalchemy.engine import Engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session
from sqlalchemy.types import JSON
from sqlalchemy.dialects.postgresql import UUID

from ..datatypes import types

Expand Down Expand Up @@ -52,3 +54,23 @@ class Entry(base):
result = session.query(Entry).one()

assert result.meta == {"hello": "world"}


def test_uuid(engine: Engine, session: Session) -> None:
base = declarative_base()

class Entry(base):
__tablename__ = "test_uuid"

id = Column(UUID, primary_key=True, default=0)

base.metadata.create_all(bind=engine)

ident = uuid4()

session.add(Entry(id=(ident)))
session.commit()

result = session.query(Entry).one()

assert result.id == ident

0 comments on commit b138b85

Please sign in to comment.