Skip to content

Commit

Permalink
Feat: Add experimental support for MariaDB (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
tebrown committed Feb 29, 2024
1 parent f13bab7 commit b95fe98
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GeoAlchemy 2 also supports the following dialects:
* `SpatiaLite <https://www.gaia-gis.it/fossil/libspatialite/home>`_ >= 4.3.0 (except for alembic
helpers that require SpatiaLite >= 5)
* `MySQL <https://dev.mysql.com/doc/refman/8.0/en/spatial-types.html>`_ >= 8
* `MariaDB <https://mariadb.com/kb/en/gis-features-in-533/>`_ >= 5.3.3 (experimental)
* `GeoPackage <http://www.geopackage.org/spec/>`_

Note that using GeoAlchemy 2 with these dialects may require some specific configuration on the
Expand Down
1 change: 1 addition & 0 deletions geoalchemy2/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
5 changes: 5 additions & 0 deletions geoalchemy2/admin/dialects/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
4 changes: 3 additions & 1 deletion geoalchemy2/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b95fe98

Please sign in to comment.