From 6980bb62d670aeacc83374e8ab12c632d2c5c88a Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Mon, 17 Aug 2015 13:42:14 -0400 Subject: [PATCH] DB: New method, db.remove_instance(instance, transaction) Delete an instance of a primary object from the database. --- gramps/gen/db/base.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gramps/gen/db/base.py b/gramps/gen/db/base.py index 34933b967..b5ec2f6ac 100644 --- a/gramps/gen/db/base.py +++ b/gramps/gen/db/base.py @@ -1844,3 +1844,27 @@ class DbWriteBase(DbReadBase): person.birth_ref_index = birth_ref_index person.death_ref_index = death_ref_index + def remove_instance(self, instance, transaction): + """ + Given the instance of an object, delete it from the database. + """ + if instance.__class__.__name__ == "Person": + self.remove_person(instance.handle, transaction) + elif instance.__class__.__name__ == "Place": + self.remove_place(instance.handle, transaction) + elif instance.__class__.__name__ == "Event": + self.remove_event(instance.handle, transaction) + elif instance.__class__.__name__ == "Repository": + self.remove_repository(instance.handle, transaction) + elif instance.__class__.__name__ == "Citation": + self.remove_citation(instance.handle, transaction) + elif instance.__class__.__name__ == "Source": + self.remove_source(instance.handle, transaction) + elif instance.__class__.__name__ == "Media": + self.remove_object(instance.handle, transaction) + elif instance.__class__.__name__ == "Note": + self.remove_note(instance.handle, transaction) + elif instance.__class__.__name__ == "Family": + self.remove_family(instance.handle, transaction) + else: + raise ValueError("invalid instance type: %s" % instance.__class__.__name__)