Skip to content

Commit

Permalink
feat: use sqlserver's unique identifier for GUID (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
cofin committed Jan 30, 2024
1 parent 65f2803 commit d9453cd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion advanced_alchemy/types/guid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from importlib.util import find_spec
from typing import TYPE_CHECKING, Any, cast

from sqlalchemy.dialects.mssql import UNIQUEIDENTIFIER as MSSQL_UNIQUEIDENTIFIER
from sqlalchemy.dialects.oracle import RAW as ORA_RAW
from sqlalchemy.dialects.postgresql import UUID as PG_UUID
from sqlalchemy.types import BINARY, CHAR, TypeDecorator
Expand Down Expand Up @@ -45,6 +46,8 @@ def load_dialect_impl(self, dialect: Dialect) -> Any:
return dialect.type_descriptor(PG_UUID())
if dialect.name == "oracle":
return dialect.type_descriptor(ORA_RAW(16))
if dialect.name == "mssql":
return dialect.type_descriptor(MSSQL_UNIQUEIDENTIFIER())
if self.binary:
return dialect.type_descriptor(BINARY(16))
return dialect.type_descriptor(CHAR(32))
Expand All @@ -56,7 +59,7 @@ def process_bind_param(
) -> bytes | str | None:
if value is None:
return value
if dialect.name in {"postgresql", "duckdb", "cockroachdb"}:
if dialect.name in {"postgresql", "duckdb", "cockroachdb", "mssql"}:
return str(value)
value = self.to_uuid(value)
if value is None:
Expand Down

0 comments on commit d9453cd

Please sign in to comment.