Skip to content

Commit

Permalink
adding new attributes in Cache.update finalyl works
Browse files Browse the repository at this point in the history
  • Loading branch information
deeenes committed Sep 17, 2024
1 parent d347beb commit 683d014
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cache_manager/_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,6 @@ def update(
key=key,
attrs=attrs,
)
print(items)
update = update or {}
main_fields = self._table_fields()
main = ', '.join(
Expand All @@ -1107,13 +1106,12 @@ def update(
for k, v in update.get('attrs', {}).items():

typ = self._sqlite_type(v)
print(v, typ, actual_typ)

if k not in main_fields and typ == actual_typ.upper():
print('HELOOOOO')

# Updating current attr
val = f'value = {self._quotes(v, typ)}'
qval = self._quotes(v, typ)
val = f'value = {qval}'
name_where = where + f' AND name = {self._quotes(k)}'
q = f'UPDATE attr_{actual_typ} SET {val} {name_where}'
self._execute(q)
Expand All @@ -1122,16 +1120,22 @@ def update(
q = f'SELECT id FROM attr_{actual_typ} {name_where}'
self._execute(q)
existing_attr_ids = set(i[0] for i in self.cur.fetchall())
print(existing_attr_ids)

new_attr_ids = set(ids) - existing_attr_ids

if not new_attr_ids:
continue

# Insert new attr to DB
new_values = ",".join(f'id = {i}, {k} = {val}' for i in new_attr_ids)
new_q = f'INSERT INTO attr_{actual_typ} ({new_values})'
new_values = ",".join(
f'{i}, NULL, 0, "{k}", {qval}'
for i in new_attr_ids
)
new_q = (
f'INSERT INTO attr_{actual_typ} '
'(id, namespace, keyvar, name, value) '
f'VALUES ({new_values})'
)
self._execute(new_q)

_log(f'Finished updating attributes')
Expand Down

0 comments on commit 683d014

Please sign in to comment.