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