Files

30 lines
1.1 KiB
Python

"""Runtime compatibility fixes for the official openGauss SQLAlchemy dialect."""
from __future__ import annotations
from sqlalchemy.dialects.postgresql.base import PGTypeCompiler
class DeerFlowOpenGaussTypeCompiler(PGTypeCompiler):
"""Render variable strings without a length for stricter GaussDB variants.
Some GaussDB PostgreSQL-compatible deployments reject ``VARCHAR(n)`` at
the numeric length token even though ordinary PostgreSQL accepts it. A
length-less ``VARCHAR`` keeps the same variable-length string semantics on
openGauss and avoids coupling the schema to that parser difference.
"""
def visit_string(self, type_, **kw): # noqa: ANN001
return "VARCHAR"
def visit_VARCHAR(self, type_, **kw): # noqa: N802, ANN001
return "VARCHAR"
def install_gauss_dialect_compatibility() -> None:
"""Install the compiler only on the openGauss async dialect class."""
from opengauss_sqlalchemy.asyncpg import OpenGaussDialect_asyncpg
OpenGaussDialect_asyncpg.type_compiler_cls = DeerFlowOpenGaussTypeCompiler