Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/db.py
Show First 20 Lines • Show All 598 Lines • ▼ Show 20 Lines | def object_find_by_sha1_git(self, ids, cur=None): | ||||
((id,) for id in ids) | ((id,) for id in ids) | ||||
) | ) | ||||
def stat_counters(self, cur=None): | def stat_counters(self, cur=None): | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
cur.execute('SELECT * FROM swh_stat_counters()') | cur.execute('SELECT * FROM swh_stat_counters()') | ||||
yield from cur | yield from cur | ||||
def origin_add(self, type, url, cur=None): | def origin_add(self, url, cur=None): | ||||
"""Insert a new origin and return the new identifier.""" | """Insert a new origin and return the new identifier.""" | ||||
insert = """INSERT INTO origin (type, url) values (%s, %s) | insert = """INSERT INTO origin (url) values (%s) | ||||
RETURNING id""" | RETURNING id""" | ||||
cur.execute(insert, (type, url)) | cur.execute(insert, (url,)) | ||||
return cur.fetchone()[0] | return cur.fetchone()[0] | ||||
origin_cols = ['id', 'type', 'url'] | origin_cols = ['id', 'url'] | ||||
def origin_get_by_url(self, origins, cur=None): | def origin_get_by_url(self, origins, cur=None): | ||||
"""Retrieve origin `(id, type, url)` from urls if found.""" | """Retrieve origin `(id, type, url)` from urls if found.""" | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
query = """SELECT %s FROM (VALUES %%s) as t(url) | query = """SELECT %s FROM (VALUES %%s) as t(url) | ||||
LEFT JOIN origin ON t.url = origin.url | LEFT JOIN origin ON t.url = origin.url | ||||
""" % ','.join('origin.' + col for col in self.origin_cols) | """ % ','.join('origin.' + col for col in self.origin_cols) | ||||
▲ Show 20 Lines • Show All 243 Lines • Show Last 20 Lines |