From b95fe98f722eca85415a997463f50422454ca5af Mon Sep 17 00:00:00 2001 From: Travis Brown Date: Thu, 29 Feb 2024 04:45:22 -0500 Subject: [PATCH] Feat: Add experimental support for MariaDB (#491) --- doc/index.rst | 1 + geoalchemy2/admin/__init__.py | 1 + geoalchemy2/admin/dialects/mysql.py | 5 +++++ geoalchemy2/types/__init__.py | 4 +++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/index.rst b/doc/index.rst index a6d38e76..e888beae 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -13,6 +13,7 @@ GeoAlchemy 2 also supports the following dialects: * `SpatiaLite `_ >= 4.3.0 (except for alembic helpers that require SpatiaLite >= 5) * `MySQL `_ >= 8 +* `MariaDB `_ >= 5.3.3 (experimental) * `GeoPackage `_ Note that using GeoAlchemy 2 with these dialects may require some specific configuration on the diff --git a/geoalchemy2/admin/__init__.py b/geoalchemy2/admin/__init__.py index f9a1212f..cb7a9b9e 100644 --- a/geoalchemy2/admin/__init__.py +++ b/geoalchemy2/admin/__init__.py @@ -19,6 +19,7 @@ def select_dialect(dialect_name): known_dialects = { "geopackage": dialects.geopackage, "mysql": dialects.mysql, + "mariadb": dialects.mysql, "postgresql": dialects.postgresql, "sqlite": dialects.sqlite, } diff --git a/geoalchemy2/admin/dialects/mysql.py b/geoalchemy2/admin/dialects/mysql.py index 71911ada..aea14654 100644 --- a/geoalchemy2/admin/dialects/mysql.py +++ b/geoalchemy2/admin/dialects/mysql.py @@ -128,6 +128,7 @@ def _compile_mysql(element, compiler, **kw): return "{}({})".format(fn, compiler.process(element.clauses, **kw)) compiles(getattr(functions, cls), "mysql")(_compile_mysql) + compiles(getattr(functions, cls), "mariadb")(_compile_mysql) def register_mysql_mapping(mapping): @@ -175,20 +176,24 @@ def _compile_GeomFromWKB_MySql(element, compiler, **kw): @compiles(functions.ST_GeomFromText, "mysql") # type: ignore +@compiles(functions.ST_GeomFromEWKB, "mariadb") # type: ignore def _MySQL_ST_GeomFromText(element, compiler, **kw): return _compile_GeomFromText_MySql(element, compiler, **kw) @compiles(functions.ST_GeomFromEWKT, "mysql") # type: ignore +@compiles(functions.ST_GeomFromEWKB, "mariadb") # type: ignore def _MySQL_ST_GeomFromEWKT(element, compiler, **kw): return _compile_GeomFromText_MySql(element, compiler, **kw) @compiles(functions.ST_GeomFromWKB, "mysql") # type: ignore +@compiles(functions.ST_GeomFromEWKB, "mariadb") # type: ignore def _MySQL_ST_GeomFromWKB(element, compiler, **kw): return _compile_GeomFromWKB_MySql(element, compiler, **kw) @compiles(functions.ST_GeomFromEWKB, "mysql") # type: ignore +@compiles(functions.ST_GeomFromEWKB, "mariadb") # type: ignore def _MySQL_ST_GeomFromEWKB(element, compiler, **kw): return _compile_GeomFromWKB_MySql(element, compiler, **kw) diff --git a/geoalchemy2/types/__init__.py b/geoalchemy2/types/__init__.py index 3708b014..effa13a0 100644 --- a/geoalchemy2/types/__init__.py +++ b/geoalchemy2/types/__init__.py @@ -39,6 +39,7 @@ def select_dialect(dialect_name): known_dialects = { "geopackage": dialects.geopackage, "mysql": dialects.mysql, + "mariadb": dialects.mysql, "postgresql": dialects.postgresql, "sqlite": dialects.sqlite, } @@ -158,7 +159,7 @@ def process(value): kwargs = {} if self.srid > 0: kwargs["srid"] = self.srid - if self.extended is not None and dialect.name != "mysql": + if self.extended is not None and dialect.name not in ["mysql", "mariadb"]: kwargs["extended"] = self.extended return self.ElementType(value, **kwargs) @@ -196,6 +197,7 @@ def check_ctor_args(geometry_type, srid, dimension, use_typmod, nullable): return geometry_type, srid +@compiles(_GISType, "mariadb") @compiles(_GISType, "mysql") def get_col_spec(self, *args, **kwargs): if self.geometry_type is not None: