"""Database operations for ACRID nodes.""" from connector_neo4j import get_session from sound_recordings.cypher import acrids as cypher from sound_recordings.utils.neo4j import by def upsert(acr_id, asset_id): """Upsert ACRID based on OrchardAsset. Args: acr_id (str): fingerprint to match asset_id (uuid): asset uuid to match Returns: bool: asset could be found by id list (str): other acrids attached to asset int: number of nodes created int: number of relationships created """ neo4j_session = get_session() results = neo4j_session.run( cypher.UPSERT, acr_id=acr_id, asset_id=str(asset_id), by=by() ) data = results.single() asset_exists = bool(data is not None) old_acrids = data['old_ids'] if data else [] summary = results.consume() return ( asset_exists, old_acrids, summary.counters.nodes_created, summary.counters.relationships_created )