Jump to: navigation, search

Database Query API

881 bytes added, 18:38, 29 January 2016
no edit summary
Starting with Gramps 5.0, there is a new method on the database object called "select." that 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 would be fast. The database select method works as follows:,
* "IS NOT"
* "IN"
Currently, value is limited to be a non-database value, such as None, a str, int, or bool. Fields are not currently allowed on the right-hand side of the operator.
* ["NOT", ("primary_name.first_name", "=", "Mary")]
Note that where expressions may be recursively nested:
* ["NOT", ["AND", ("primary_name.first_name", "=", "Mary"), ("gramps_id", "=", "I0003")]]
The goal is to always have a query, and to always have expanded be False. Those will be the fastest queries.
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.
== Implementation ==
In the last example, the "surname" field was applied to each of the surname_list items.
Each primary object can also have a list of extra secondary fields/indexes. These are specified in the primary object's method "get_extra_secondary_fields()" which returns a list of dotted-path strings.
The dotted-field path strings are mapped to SQL names by replacing dots with two underscores.
== Speed Tests ==

Navigation menu