Jump to: navigation, search

Database Query API

443 bytes added, 18:48, 29 January 2016
no edit summary
Starting with Gramps 5.0, there is a new method on the database object called "select." The goal of select is to make it possible to select most any data, based on most any criteria, sorted in most any order. In addition, where possible, it the selection would be as fastas possible.
The database select method works as follows:
== Result ==
The method will always return a Result. A result is a collection of all of the data (ie, it is not a generator). You can find out how many records are returned with len(result).
Results are a subclass of the Python list object, with additional properties:
* - total number of records (in the case of start or limit is given. In that case len(result) !=* result.time - the time in seconds it too to collect the data* result.expanded - whether the data needed to be expanded (unpickled and primary objects created). BSDDB selects alway are expanded* result.query - the actual SQL query, if one
The When writing selects, the goal is to always have a query, and to always have expanded be False. Those will be the fastest queries. However, of course, that is not always possible. With BSDDB databases, there will never be a query, and the data will always be expanded.
Each element in the Result list is a dictionary of dotted-field path strings and their data (if any). If a value is None, it either means that the value is None, or that there is no such field for this primary object.For example:  [{"gramps_id": "I0000"}, {"gramps_id": "I0001"}, {"gramps_id": "I0002"}, {"gramps_id": "I0003"}, ...]
== Implementation ==
* person.primary_name.first_name
respectively. We could can make special fields for these, and special indexes. Gramps 5.0 creates "secondary" fields and indexes in SQL for every str, int, or bool data on a primary object. These secondary fields are known from the primary object's schema.
The schema idea has been augmented with additional methods based on the idea of "fields". Now, you can ask a person object:

Navigation menu