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 | ||||
fetch_history_cols = ['origin', 'date', 'status', 'result', 'stdout', | |||||
'stderr', 'duration'] | |||||
def create_fetch_history(self, fetch_history, cur=None): | |||||
"""Create a fetch_history entry with the data in fetch_history""" | |||||
cur = self._cursor(cur) | |||||
query = '''INSERT INTO fetch_history (%s) | |||||
VALUES (%s) RETURNING id''' % ( | |||||
','.join(self.fetch_history_cols), | |||||
','.join(['%s'] * len(self.fetch_history_cols)) | |||||
) | |||||
cur.execute(query, [fetch_history.get(col) for col in | |||||
self.fetch_history_cols]) | |||||
return cur.fetchone()[0] | |||||
def get_fetch_history(self, fetch_history_id, cur=None): | |||||
"""Get a fetch_history entry with the given id""" | |||||
cur = self._cursor(cur) | |||||
query = '''SELECT %s FROM fetch_history WHERE id=%%s''' % ( | |||||
', '.join(self.fetch_history_cols), | |||||
) | |||||
cur.execute(query, (fetch_history_id,)) | |||||
data = cur.fetchone() | |||||
if not data: | |||||
return None | |||||
ret = {'id': fetch_history_id} | |||||
for i, col in enumerate(self.fetch_history_cols): | |||||
ret[col] = data[i] | |||||
return ret | |||||
def update_fetch_history(self, fetch_history, cur=None): | |||||
"""Update the fetch_history entry from the data in fetch_history""" | |||||
cur = self._cursor(cur) | |||||
query = '''UPDATE fetch_history | |||||
SET %s | |||||
WHERE id=%%s''' % ( | |||||
','.join('%s=%%s' % col for col in self.fetch_history_cols) | |||||
) | |||||
cur.execute(query, [jsonize(fetch_history.get(col)) for col in | |||||
self.fetch_history_cols + ['id']]) | |||||
def origin_add(self, type, url, cur=None): | def origin_add(self, type, 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 (type, url) values (%s, %s) | ||||
RETURNING id""" | RETURNING id""" | ||||
cur.execute(insert, (type, url)) | cur.execute(insert, (type, url)) | ||||
return cur.fetchone()[0] | return cur.fetchone()[0] | ||||
▲ Show 20 Lines • Show All 252 Lines • Show Last 20 Lines |