Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/postgresql/db.py
Show All 22 Lines | def jsonize(d): | ||||
return _jsonize(dict(d) if d is not None else None) | return _jsonize(dict(d) if d is not None else None) | ||||
class Db(BaseDb): | class Db(BaseDb): | ||||
"""Proxy to the SWH DB, with wrappers around stored procedures | """Proxy to the SWH DB, with wrappers around stored procedures | ||||
""" | """ | ||||
current_version = 164 | current_version = 165 | ||||
def mktemp_dir_entry(self, entry_type, cur=None): | def mktemp_dir_entry(self, entry_type, cur=None): | ||||
self._cursor(cur).execute( | self._cursor(cur).execute( | ||||
"SELECT swh_mktemp_dir_entry(%s)", (("directory_entry_%s" % entry_type),) | "SELECT swh_mktemp_dir_entry(%s)", (("directory_entry_%s" % entry_type),) | ||||
) | ) | ||||
@stored_procedure("swh_mktemp_revision") | @stored_procedure("swh_mktemp_revision") | ||||
def mktemp_revision(self, cur=None): | def mktemp_revision(self, cur=None): | ||||
▲ Show 20 Lines • Show All 209 Lines • ▼ Show 20 Lines | class Db(BaseDb): | ||||
snapshot_get_cols = ["snapshot_id", "name", "target", "target_type"] | snapshot_get_cols = ["snapshot_id", "name", "target", "target_type"] | ||||
def snapshot_get_by_id( | def snapshot_get_by_id( | ||||
self, | self, | ||||
snapshot_id, | snapshot_id, | ||||
branches_from=b"", | branches_from=b"", | ||||
branches_count=None, | branches_count=None, | ||||
target_types=None, | target_types=None, | ||||
branches_name_pattern=None, | |||||
cur=None, | cur=None, | ||||
): | ): | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
query = """\ | query = """\ | ||||
SELECT %s | SELECT %s | ||||
FROM swh_snapshot_get_by_id(%%s, %%s, %%s, %%s :: snapshot_target[]) | FROM swh_snapshot_get_by_id(%%s, %%s, %%s, %%s :: snapshot_target[], %%s) | ||||
""" % ", ".join( | """ % ", ".join( | ||||
self.snapshot_get_cols | self.snapshot_get_cols | ||||
) | ) | ||||
cur.execute(query, (snapshot_id, branches_from, branches_count, target_types)) | cur.execute( | ||||
query, | |||||
( | |||||
snapshot_id, | |||||
branches_from, | |||||
branches_count, | |||||
target_types, | |||||
branches_name_pattern, | |||||
), | |||||
) | |||||
yield from cur | yield from cur | ||||
def snapshot_get_random(self, cur=None): | def snapshot_get_random(self, cur=None): | ||||
return self._get_random_row_from_table("snapshot", ["id"], "id", cur) | return self._get_random_row_from_table("snapshot", ["id"], "id", cur) | ||||
content_find_cols = [ | content_find_cols = [ | ||||
"sha1", | "sha1", | ||||
▲ Show 20 Lines • Show All 1,079 Lines • Show Last 20 Lines |