Skip to content

Commit

Permalink
fix: correct json type mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Mause committed Jan 8, 2023
1 parent c6484a3 commit 7bf8753
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions duckdb_engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class Dialect(PGDialect_psycopg2):
# postgres type_codes (such as 701 for float) that duckdb doesn't have
sqltypes.Numeric: sqltypes.Numeric,
sqltypes.Interval: sqltypes.Interval,
sqltypes.JSON: sqltypes.JSON,
},
)

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

from pytest import mark
from sqlalchemy import Column, Integer
from sqlalchemy import Column, Integer, select
from sqlalchemy.engine import Engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session
from sqlalchemy.types import JSON

from ..datatypes import types

Expand Down Expand Up @@ -32,3 +33,22 @@ def test_unsigned_integer_type(
session.commit()

assert session.query(table).one()


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

class Entry(base):
__tablename__ = "test_json"

id = Column(Integer, primary_key=True, default=0)
meta = Column(JSON, nullable=False)

base.metadata.create_all(bind=engine)

session.add(Entry(meta={"hello": "world"})) # type: ignore[call-arg]
session.commit()

result = session.scalar(select(Entry))

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

0 comments on commit 7bf8753

Please sign in to comment.