from guillotina.db.storages.utils import clear_table_name from guillotina.db.storages.utils import get_table_definition from guillotina.db.storages.utils import register_sql from guillotina.exceptions import ConflictError from guillotina.exceptions import ConflictIdOnContainer from guillotina.exceptions import TIDConflictError from guillotina.profile import profilable from zope.interface import implementer log = logging.getLogger("guillotina.storage") # we can not use FOR UPDATE or FOR SHARE unfortunately because # it can cause deadlocks on the database--we need to resolve them ourselves register_sql( 'GET_OID', f""" SELECT zoid, tid, state_size, resource, of, parent_id, id, type, state FROM {{table_name}} WHERE zoid = $1::varchar({MAX_UID_LENGTH}) """) register_sql( 'GET_CHILDREN_KEYS', f""" SELECT id FROM {{table_name}} WHERE parent_id = $1::varchar({MAX_UID_LENGTH}) """) register_sql( 'GET_ANNOTATIONS_KEYS', f""" SELECT id, parent_id FROM {{table_name}} WHERE of = $1::varchar({MAX_UID_LENGTH})
exception when invalid_text_representation then return CAST('1970-01-01T00:00:00Z' AS timestamptz); when datetime_field_overflow then return CAST('1970-01-01T00:00:00Z' AS timestamptz); end; $$ language plpgsql immutable; """ ] # Reindex logic register_sql( "JSONB_UPDATE", f""" UPDATE {{table_name}} SET json = $2::json WHERE zoid = $1::varchar({MAX_UID_LENGTH})""", ) class ParsedQueryInfo(BasicParsedQueryInfo): wheres: typing.List[typing.Any] wheres_arguments: typing.List[typing.Any] selects: typing.List[str] selects_arguments: typing.List[typing.Any] _type_mapping = {"int": int, "float": float}
from guillotina.const import TRASHED_ID from guillotina.db.interfaces import ICockroachStorage from guillotina.db.interfaces import IPostgresStorage from guillotina.db.interfaces import IVacuumProvider from guillotina.db.storages.utils import register_sql import asyncio import asyncpg.exceptions import logging logger = logging.getLogger("guillotina") register_sql( "DELETE_TRASHED_OBJECTS", f""" DELETE FROM {{table_name}} WHERE zoid = ANY($1) AND parent_id = '{TRASHED_ID}'; """, ) register_sql( "GET_BATCH_OF_TRASHED_OBJECTS", f""" SELECT zoid from {{table_name}} where parent_id = '{TRASHED_ID}' LIMIT $1; """, ) register_sql( "TRASH_BATCH", f"""
from guillotina.exceptions import TIDConflictError logger = glogging.getLogger('guillotina') # upsert without checking matching tids on updated object register_sql('CR_NAIVE_UPSERT', f""" INSERT INTO {{table_name}} (zoid, tid, state_size, part, resource, of, otid, parent_id, id, type, state) VALUES ($1::varchar({MAX_OID_LENGTH}), $2::int, $3::int, $4::int, $5::boolean, $6::varchar({MAX_OID_LENGTH}), $7::int, $8::varchar({MAX_OID_LENGTH}), $9::text, $10::text, $11::bytea) ON CONFLICT (zoid) DO UPDATE SET tid = EXCLUDED.tid, state_size = EXCLUDED.state_size, part = EXCLUDED.part, resource = EXCLUDED.resource, of = EXCLUDED.of, otid = EXCLUDED.otid, parent_id = EXCLUDED.parent_id, id = EXCLUDED.id, type = EXCLUDED.type, state = EXCLUDED.state RETURNING NOTHING""") # update without checking matching tids on updated object register_sql('CR_UPDATE', f""" UPDATE {{table_name}} SET
from guillotina.db.storages.utils import register_sql from guillotina.exceptions import ConflictError from guillotina.exceptions import ConflictIdOnContainer from guillotina.exceptions import TIDConflictError from guillotina.profile import profilable from zope.interface import implementer log = logging.getLogger("guillotina.storage") # we can not use FOR UPDATE or FOR SHARE unfortunately because # it can cause deadlocks on the database--we need to resolve them ourselves register_sql('GET_OID', f""" SELECT zoid, tid, state_size, resource, of, parent_id, id, type, state FROM {{table_name}} WHERE zoid = $1::varchar({MAX_OID_LENGTH}) """) register_sql('GET_CHILDREN_KEYS', f""" SELECT id FROM {{table_name}} WHERE parent_id = $1::varchar({MAX_OID_LENGTH}) """) register_sql('GET_ANNOTATIONS_KEYS', f""" SELECT id, parent_id FROM {{table_name}} WHERE of = $1::varchar({MAX_OID_LENGTH}) """)