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
8from __future__ import annotations
9
10from typing import Any
11from typing import Callable
12
13from .base import MariaDBIdentifierPreparer
14from .base import MySQLDialect
15from .base import MySQLIdentifierPreparer
16from .base import MySQLTypeCompiler
17from ...sql import sqltypes
18
19
20class INET4(sqltypes.TypeEngine[str]):
21 """INET4 column type for MariaDB
22
23 .. versionadded:: 2.0.37
24 """
25
26 __visit_name__ = "INET4"
27
28
29class INET6(sqltypes.TypeEngine[str]):
30 """INET6 column type for MariaDB
31
32 .. versionadded:: 2.0.37
33 """
34
35 __visit_name__ = "INET6"
36
37
38class MariaDBTypeCompiler(MySQLTypeCompiler):
39 def visit_INET4(self, type_: INET4, **kwargs: Any) -> str:
40 return "INET4"
41
42 def visit_INET6(self, type_: INET6, **kwargs: Any) -> str:
43 return "INET6"
44
45
46class MariaDBDialect(MySQLDialect):
47 is_mariadb = True
48 supports_statement_cache = True
49 name = "mariadb"
50 preparer: type[MySQLIdentifierPreparer] = MariaDBIdentifierPreparer
51 type_compiler_cls = MariaDBTypeCompiler
52
53
54def loader(driver: str) -> Callable[[], type[MariaDBDialect]]:
55 dialect_mod = __import__(
56 "sqlalchemy.dialects.mysql.%s" % driver
57 ).dialects.mysql
58
59 driver_mod = getattr(dialect_mod, driver)
60 if hasattr(driver_mod, "mariadb_dialect"):
61 driver_cls = driver_mod.mariadb_dialect
62 return driver_cls # type: ignore[no-any-return]
63 else:
64 driver_cls = driver_mod.dialect
65
66 return type(
67 "MariaDBDialect_%s" % driver,
68 (
69 MariaDBDialect,
70 driver_cls,
71 ),
72 {"supports_statement_cache": True},
73 )