X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/6e89310a9285f1ad15d8002bf68f578eada367a0..d856788bf5cf7b4b3e2b4de10f37cf3002ae6826:/src/nominatim_db/data/country_info.py diff --git a/src/nominatim_db/data/country_info.py b/src/nominatim_db/data/country_info.py index 35943a50..9b714059 100644 --- a/src/nominatim_db/data/country_info.py +++ b/src/nominatim_db/data/country_info.py @@ -9,12 +9,11 @@ Functions for importing and managing static country information. """ from typing import Dict, Any, Iterable, Tuple, Optional, Container, overload from pathlib import Path -import psycopg2.extras -from nominatim_core.db import utils as db_utils -from nominatim_core.db.connection import connect, Connection -from nominatim_core.errors import UsageError -from nominatim_core.config import Configuration +from ..db import utils as db_utils +from ..db.connection import connect, Connection, register_hstore +from ..errors import UsageError +from ..config import Configuration from ..tokenizer.base import AbstractTokenizer def _flatten_name_list(names: Any) -> Dict[str, str]: @@ -129,8 +128,8 @@ def setup_country_tables(dsn: str, sql_dir: Path, ignore_partitions: bool = Fals params.append((ccode, props['names'], lang, partition)) with connect(dsn) as conn: + register_hstore(conn) with conn.cursor() as cur: - psycopg2.extras.register_hstore(cur) cur.execute( """ CREATE TABLE public.country_name ( country_code character varying(2), @@ -139,9 +138,10 @@ def setup_country_tables(dsn: str, sql_dir: Path, ignore_partitions: bool = Fals country_default_language_code text, partition integer ); """) - cur.execute_values( + cur.executemany( """ INSERT INTO public.country_name - (country_code, name, country_default_language_code, partition) VALUES %s + (country_code, name, country_default_language_code, partition) + VALUES (%s, %s, %s, %s) """, params) conn.commit() @@ -157,8 +157,8 @@ def create_country_names(conn: Connection, tokenizer: AbstractTokenizer, return ':' not in key or not languages or \ key[key.index(':') + 1:] in languages + register_hstore(conn) with conn.cursor() as cur: - psycopg2.extras.register_hstore(cur) cur.execute("""SELECT country_code, name FROM country_name WHERE country_code is not null""")