X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/a413aae8a3962be4d623844d867604df68a9a211..37940803273aeab88ae37f8f6c9698478df52fc2:/nominatim/db/sqlalchemy_schema.py diff --git a/nominatim/db/sqlalchemy_schema.py b/nominatim/db/sqlalchemy_schema.py index 550f1f12..2ca518ca 100644 --- a/nominatim/db/sqlalchemy_schema.py +++ b/nominatim/db/sqlalchemy_schema.py @@ -10,16 +10,18 @@ SQLAlchemy definitions for all tables used by the frontend. from typing import Any import sqlalchemy as sa -from geoalchemy2 import Geometry -from sqlalchemy.dialects.postgresql import HSTORE, ARRAY, JSONB +from sqlalchemy.dialects.postgresql import HSTORE, ARRAY, JSONB, array from sqlalchemy.dialects.sqlite import JSON as sqlite_json +from nominatim.db.sqlalchemy_types import Geometry + class PostgresTypes: """ Type definitions for complex types as used in Postgres variants. """ Composite = HSTORE Json = JSONB IntArray = ARRAY(sa.Integer()) #pylint: disable=invalid-name + to_array = array class SqliteTypes: @@ -29,6 +31,12 @@ class SqliteTypes: Json = sqlite_json IntArray = sqlite_json + @staticmethod + def to_array(arr: Any) -> Any: + """ Sqlite has no special conversion for arrays. + """ + return arr + #pylint: disable=too-many-instance-attributes class SearchTables: @@ -72,12 +80,12 @@ class SearchTables: sa.Column('name', self.types.Composite), sa.Column('address', self.types.Composite), sa.Column('extratags', self.types.Composite), - sa.Column('geometry', Geometry(srid=4326), nullable=False), + sa.Column('geometry', Geometry, nullable=False), sa.Column('wikipedia', sa.Text), sa.Column('country_code', sa.String(2)), sa.Column('housenumber', sa.Text), sa.Column('postcode', sa.Text), - sa.Column('centroid', Geometry(srid=4326, spatial_index=False))) + sa.Column('centroid', Geometry)) self.addressline = sa.Table('place_addressline', meta, sa.Column('place_id', sa.BigInteger, index=True), @@ -96,7 +104,7 @@ class SearchTables: sa.Column('indexed_date', sa.DateTime), sa.Column('country_code', sa.String(2)), sa.Column('postcode', sa.Text, index=True), - sa.Column('geometry', Geometry(srid=4326))) + sa.Column('geometry', Geometry)) self.osmline = sa.Table('location_property_osmline', meta, sa.Column('place_id', sa.BigInteger, nullable=False, unique=True), @@ -108,7 +116,7 @@ class SearchTables: sa.Column('step', sa.SmallInteger), sa.Column('partition', sa.SmallInteger), sa.Column('indexed_status', sa.SmallInteger), - sa.Column('linegeo', Geometry(srid=4326)), + sa.Column('linegeo', Geometry), sa.Column('address', self.types.Composite), sa.Column('postcode', sa.Text), sa.Column('country_code', sa.String(2))) @@ -123,7 +131,7 @@ class SearchTables: self.country_grid = sa.Table('country_osm_grid', meta, sa.Column('country_code', sa.String(2)), sa.Column('area', sa.Float), - sa.Column('geometry', Geometry(srid=4326))) + sa.Column('geometry', Geometry)) # The following tables are not necessarily present. self.search_name = sa.Table('search_name', meta, @@ -134,7 +142,7 @@ class SearchTables: sa.Column('name_vector', self.types.IntArray, index=True), sa.Column('nameaddress_vector', self.types.IntArray, index=True), sa.Column('country_code', sa.String(2)), - sa.Column('centroid', Geometry(srid=4326))) + sa.Column('centroid', Geometry)) self.tiger = sa.Table('location_property_tiger', meta, sa.Column('place_id', sa.BigInteger), @@ -143,5 +151,5 @@ class SearchTables: sa.Column('endnumber', sa.Integer), sa.Column('step', sa.SmallInteger), sa.Column('partition', sa.SmallInteger), - sa.Column('linegeo', Geometry(srid=4326, spatial_index=False)), + sa.Column('linegeo', Geometry), sa.Column('postcode', sa.Text))