from typing import Optional, Tuple, Any, cast
import logging
-from psycopg2.extras import Json
-from psycopg2 import DataError
+import psycopg
+from psycopg.types.json import Json
from ..typing import DictCursorResult
from ..config import Configuration
LOG = logging.getLogger()
+
def _get_place_info(cursor: Cursor, osm_id: Optional[str],
place_id: Optional[int]) -> DictCursorResult:
sql = """SELECT place_id, extra.*
"""
with connect(config.get_libpq_dsn()) as conn:
register_hstore(conn)
- with conn.cursor() as cur:
+ with conn.cursor(row_factory=psycopg.rows.dict_row) as cur:
place = _get_place_info(cur, osm_id, place_id)
cur.execute("update placex set indexed_status = 2 where place_id = %s",
tokenizer = tokenizer_factory.get_tokenizer_for_db(config)
+ # Enable printing of messages.
+ conn.add_notice_handler(lambda diag: print(diag.message_primary))
+
with tokenizer.name_analyzer() as analyzer:
cur.execute("""UPDATE placex
SET indexed_status = 0, address = %s, token_info = %s,
# we do not want to keep the results
conn.rollback()
- for msg in conn.notices:
- print(msg)
-
def clean_deleted_relations(config: Configuration, age: str) -> None:
""" Clean deleted relations older than a given age
WHERE p.osm_type = d.osm_type AND p.osm_id = d.osm_id
AND age(p.indexed_date) > %s::interval""",
(age, ))
- except DataError as exc:
+ except psycopg.DataError as exc:
raise UsageError('Invalid PostgreSQL time interval format') from exc
conn.commit()