mariadb.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # dialects/mysql/mariadb.py
  2. # Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
  3. # <see AUTHORS file>
  4. #
  5. # This module is part of SQLAlchemy and is released under
  6. # the MIT License: https://www.opensource.org/licenses/mit-license.php
  7. from __future__ import annotations
  8. from typing import Any
  9. from .base import MariaDBIdentifierPreparer
  10. from .base import MySQLDialect
  11. from .base import MySQLIdentifierPreparer
  12. from .base import MySQLTypeCompiler
  13. from ...sql import sqltypes
  14. class INET4(sqltypes.TypeEngine[str]):
  15. """INET4 column type for MariaDB
  16. .. versionadded:: 2.0.37
  17. """
  18. __visit_name__ = "INET4"
  19. class INET6(sqltypes.TypeEngine[str]):
  20. """INET6 column type for MariaDB
  21. .. versionadded:: 2.0.37
  22. """
  23. __visit_name__ = "INET6"
  24. class MariaDBTypeCompiler(MySQLTypeCompiler):
  25. def visit_INET4(self, type_: INET4, **kwargs: Any) -> str:
  26. return "INET4"
  27. def visit_INET6(self, type_: INET6, **kwargs: Any) -> str:
  28. return "INET6"
  29. class MariaDBDialect(MySQLDialect):
  30. is_mariadb = True
  31. supports_statement_cache = True
  32. name = "mariadb"
  33. preparer: type[MySQLIdentifierPreparer] = MariaDBIdentifierPreparer
  34. type_compiler_cls = MariaDBTypeCompiler
  35. def loader(driver: str) -> type[MariaDBDialect]:
  36. dialect_mod = __import__(
  37. "sqlalchemy.dialects.mysql.%s" % driver
  38. ).dialects.mysql
  39. driver_mod = getattr(dialect_mod, driver)
  40. if hasattr(driver_mod, "mariadb_dialect"):
  41. driver_cls = driver_mod.mariadb_dialect
  42. return driver_cls # type: ignore[no-any-return]
  43. else:
  44. driver_cls = driver_mod.dialect
  45. return type(
  46. "MariaDBDialect_%s" % driver,
  47. (
  48. MariaDBDialect,
  49. driver_cls,
  50. ),
  51. {"supports_statement_cache": True},
  52. )