Difference between revisions of "Addon:Generic DB Access lib"
(copied from original article - still needs to reworked and tested) |
|||
Line 5: | Line 5: | ||
=== Example === | === Example === | ||
+ | Here is how you would solve the above using this experimental Gramps addon: | ||
+ | |||
+ | <pre> | ||
+ | from libaccess import * | ||
+ | init(dbstate.db) | ||
+ | len([p for p in Person.all() if p.birth.date.month == 3]) | ||
+ | </pre> | ||
+ | |||
+ | That’s it. Now there’s quite a bit going on here, but I think the most interesting is that this works even if a person doesn’t have a birth event, or if the birth event happens to be missing (eg, the database is in an inconsistent state). By allowing this, it makes chained accessors (item.item.item) possible to use to get to the endpoint to make the comparison (month == 3). Also, one doesn’t need to know anything about the database or gen.lib objects other than the field names we’re interested in. | ||
==See also== | ==See also== |
Revision as of 07:11, 13 May 2020
This is a Third-party Addon. Please use carefully on data that is backed up, and help make it better by reporting any comments or problems to the author, or issues to the bug tracker |
The Generic DB Access lib (AKA libaccess) is an experimental library that provides generic access to the database and the gen.lib interface(AKA The core library of Gramps objects ). It was designed to simplify the manner in which developers interact with Gramps.
This article's content is incomplete or a placeholder stub. |
Usage
Example
Here is how you would solve the above using this experimental Gramps addon:
from libaccess import * init(dbstate.db) len([p for p in Person.all() if p.birth.date.month == 3])
That’s it. Now there’s quite a bit going on here, but I think the most interesting is that this works even if a person doesn’t have a birth event, or if the birth event happens to be missing (eg, the database is in an inconsistent state). By allowing this, it makes chained accessors (item.item.item) possible to use to get to the endpoint to make the comparison (month == 3). Also, one doesn’t need to know anything about the database or gen.lib objects other than the field names we’re interested in.
See also
- Alternative Interfaces, Date: January 23rd, 2010, by Doug Blank, who introduced libaccess in Gramps 3.2.
- Source code for Gramps master: https://github.com/gramps-project/addons-source/tree/master/libaccess
- GEPS 017: Flexible gen.lib Interface - Proposal was withdrawn as after building a prototype, it was found to be too slow for general use.