Skip to content

Commit

Permalink
Generic needs to handle both blob and json during upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
dsblank committed Oct 13, 2024
1 parent e677833 commit 7ac4f7b
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions gramps/gen/db/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,10 @@ def _get_from_handle(self, obj_key, obj_class, handle):
raise HandleError("Handle is empty")
data = self._get_raw_data(obj_key, handle)
if data:
return from_dict(data)
if self._data_field == "json_data":
return from_dict(data)
else:
return obj_class.create(data)
raise HandleError(f"Handle {handle} not found")

def get_event_from_handle(self, handle):
Expand Down Expand Up @@ -1397,39 +1400,63 @@ def get_tag_from_handle(self, handle):

def get_person_from_gramps_id(self, gramps_id):
data = self._get_raw_person_from_id_data(gramps_id)
return from_dict(data)
if self._data_field == "json_data":
return from_dict(data)
else:
return Person.create(data)

def get_family_from_gramps_id(self, gramps_id):
data = self._get_raw_family_from_id_data(gramps_id)
return from_dict(data)
if self._data_field == "json_data":
return from_dict(data)
else:
return Family.create(data)

def get_citation_from_gramps_id(self, gramps_id):
data = self._get_raw_citation_from_id_data(gramps_id)
return from_dict(data)
if self._data_field == "json_data":
return from_dict(data)
else:
return Citation.create(data)

def get_source_from_gramps_id(self, gramps_id):
data = self._get_raw_source_from_id_data(gramps_id)
return from_dict(data)
if self._data_field == "json_data":
return from_dict(data)
else:
return Source.create(data)

def get_event_from_gramps_id(self, gramps_id):
data = self._get_raw_event_from_id_data(gramps_id)
return from_dict(data)
if self._data_field == "json_data":
return from_dict(data)
else:
return Event.create(data)

def get_media_from_gramps_id(self, gramps_id):
data = self._get_raw_media_from_id_data(gramps_id)
return from_dict(data)
if self._data_field == "json_data":
return from_dict(data)
else:
return Media.create(data)

def get_place_from_gramps_id(self, gramps_id):
data = self._get_raw_place_from_id_data(gramps_id)
return from_dict(data)
if self._data_field == "json_data":
return from_dict(data)
else:
return Place.create(data)

def get_repository_from_gramps_id(self, gramps_id):
data = self._get_raw_repository_from_id_data(gramps_id)
return from_dict(data)

def get_note_from_gramps_id(self, gramps_id):
data = self._get_raw_note_from_id_data(gramps_id)
return from_dict(data)
if self._data_field == "json_data":
return from_dict(data)
else:
return Note.create(data)

################################################################
#
Expand Down Expand Up @@ -1630,7 +1657,10 @@ def _iter_objects(self, class_):
"""
cursor = self._get_table_func(class_.__name__, "cursor_func")
for data in cursor():
yield from_dict(data[1])
if self._data_field == "json_data":
return from_dict(data[1])
else:
return class_.create(data[1])

def iter_people(self):
return self._iter_objects(Person)
Expand Down Expand Up @@ -2701,3 +2731,6 @@ def set_schema_version(self, value):

def upgrade_table_for_json_access(self, table_name):
pass

def _setup_data_access(self, format):
pass

0 comments on commit 7ac4f7b

Please sign in to comment.