mariadb.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # dialects/mysql/mariadb.py
  2. # Copyright (C) 2005-2025 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. # mypy: ignore-errors
  8. from .base import MariaDBIdentifierPreparer
  9. from .base import MySQLDialect
  10. from .base import MySQLTypeCompiler
  11. from ...sql import sqltypes
  12. class INET4(sqltypes.TypeEngine[str]):
  13. """INET4 column type for MariaDB
  14. .. versionadded:: 2.0.37
  15. """
  16. __visit_name__ = "INET4"
  17. class INET6(sqltypes.TypeEngine[str]):
  18. """INET6 column type for MariaDB
  19. .. versionadded:: 2.0.37
  20. """
  21. __visit_name__ = "INET6"
  22. class MariaDBTypeCompiler(MySQLTypeCompiler):
  23. def visit_INET4(self, type_, **kwargs) -> str:
  24. return "INET4"
  25. def visit_INET6(self, type_, **kwargs) -> str:
  26. return "INET6"
  27. class MariaDBDialect(MySQLDialect):
  28. is_mariadb = True
  29. supports_statement_cache = True
  30. name = "mariadb"
  31. preparer = MariaDBIdentifierPreparer
  32. type_compiler_cls = MariaDBTypeCompiler
  33. def loader(driver):
  34. dialect_mod = __import__(
  35. "sqlalchemy.dialects.mysql.%s" % driver
  36. ).dialects.mysql
  37. driver_mod = getattr(dialect_mod, driver)
  38. if hasattr(driver_mod, "mariadb_dialect"):
  39. driver_cls = driver_mod.mariadb_dialect
  40. return driver_cls
  41. else:
  42. driver_cls = driver_mod.dialect
  43. return type(
  44. "MariaDBDialect_%s" % driver,
  45. (
  46. MariaDBDialect,
  47. driver_cls,
  48. ),
  49. {"supports_statement_cache": True},
  50. )