Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/postgresql/provenancedb_base.py
Show All 19 Lines | from ..interface import ( | ||||
ProvenanceResult, | ProvenanceResult, | ||||
RelationData, | RelationData, | ||||
RelationType, | RelationType, | ||||
RevisionData, | RevisionData, | ||||
) | ) | ||||
class ProvenanceDBBase: | class ProvenanceDBBase: | ||||
raise_on_commit: bool = False | def __init__( | ||||
self, conn: psycopg2.extensions.connection, raise_on_commit: bool = False | |||||
def __init__(self, conn: psycopg2.extensions.connection): | ): | ||||
BaseDb.adapt_conn(conn) | BaseDb.adapt_conn(conn) | ||||
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) | conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) | ||||
conn.set_session(autocommit=True) | conn.set_session(autocommit=True) | ||||
self.conn = conn | self.conn = conn | ||||
self.cursor = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) | self.cursor = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) | ||||
# XXX: not sure this is the best place to do it! | # XXX: not sure this is the best place to do it! | ||||
sql = "SET timezone TO 'UTC'" | sql = "SET timezone TO 'UTC'" | ||||
self.cursor.execute(sql) | self.cursor.execute(sql) | ||||
self._flavor: Optional[str] = None | self._flavor: Optional[str] = None | ||||
self.raise_on_commit = raise_on_commit | |||||
@property | @property | ||||
def flavor(self) -> str: | def flavor(self) -> str: | ||||
if self._flavor is None: | if self._flavor is None: | ||||
sql = "SELECT swh_get_dbflavor() AS flavor" | sql = "SELECT swh_get_dbflavor() AS flavor" | ||||
self.cursor.execute(sql) | self.cursor.execute(sql) | ||||
self._flavor = self.cursor.fetchone()["flavor"] | self._flavor = self.cursor.fetchone()["flavor"] | ||||
assert self._flavor is not None | assert self._flavor is not None | ||||
return self._flavor | return self._flavor | ||||
@property | |||||
def with_path(self) -> bool: | def with_path(self) -> bool: | ||||
return self.flavor == "with-path" | return self.flavor == "with-path" | ||||
def content_find_first(self, id: Sha1Git) -> Optional[ProvenanceResult]: | def content_find_first(self, id: Sha1Git) -> Optional[ProvenanceResult]: | ||||
... | ... | ||||
def content_find_all( | def content_find_all( | ||||
self, id: Sha1Git, limit: Optional[int] = None | self, id: Sha1Git, limit: Optional[int] = None | ||||
▲ Show 20 Lines • Show All 261 Lines • Show Last 20 Lines |