Add retrieve all item_id for each field assosiated to a notes

This commit is contained in:
un-pogaz 2023-09-22 10:19:43 +02:00 committed by Kovid Goyal
parent 5657b04d50
commit 4e878b14cc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 15 additions and 0 deletions

View File

@ -975,6 +975,9 @@ class DB:
def notes_data_for(self, field_name, item_id):
return self.notes.get_note_data(self.conn, field_name, item_id)
def get_notes_id_map(self):
return self.notes.get_note_id_map(self.conn)
def set_notes_for(self, field, item_id, doc: str, searchable_text: str, resource_hashes, remove_unused_resources) -> int:
id_val = self.tables[field].id_map[item_id]
note_id = self.notes.set_note(self.conn, field, item_id, id_val, doc, resource_hashes, searchable_text)

View File

@ -686,6 +686,10 @@ class Cache:
' Return all notes data as a dict or None if note does not exist '
return self.backend.notes_data_for(field, item_id)
def get_notes_id_map(self) -> dict:
' Return all item_id for each field assosiated to a notes. '
return self.backend.get_notes_id_map()
@read_api
def field_supports_notes(self, field) -> bool:
' Return True iff the specified field supports notes '

View File

@ -269,6 +269,14 @@ class Notes:
'resource_hashes': frozenset(self.resources_used_by(conn, note_id)),
}
def get_note_id_map(self, conn):
rslt = {}
for (note_id, field_name) in conn.execute('SELECT id,colname FROM notes_db.notes'):
if field_name not in rslt:
rslt[field_name] = []
rslt[field_name].append(note_id)
return rslt
def rename_note(self, conn, field_name, old_item_id, new_item_id, new_item_value):
note_id = self.note_id_for(conn, field_name, old_item_id)
if note_id is None: