Changes

Jump to: navigation, search

Database Query API

285 bytes added, 17:30, 29 January 2016
no edit summary
[This == Overview == Starting with Gramps 5.0, there is a work in progressnew method on the database object called "select" that works as follows:  db.]select(TABLE-NAME, SELECT-LIST, where=WHERE-LIST, order_by=ORDER-BY-LIST) As an example, consider selecting the gramps_id from all people who have a surname of "Smith" and whose name begins with a "J", ordered by the gramps_id:
db.select("Person", ["gramps_id"], where=["AND", [("primary_name.surname_list.0.surname", "= Overview ", "Smith"), ("primary_name.first_name", "LIKE", "J%")]], order_by=[("gramps_id", "ASC")]) == Implementation ==
Starting with Gramps 5.0, there There are now two database backends, : Berkeley DB (BSDDB), and [https://www.python.org/dev/peps/pep-0249/ Python's DB-API]. BSDDB is a data store with much of the database code written in Python, and DB-API is a common interface to the popular SQL engines. We have used BSDDB in Gramps for many years. , but are now transitioning to DB-API is a common interface to the popular SQL engines.
PreviouslyWith BSDDB, Gramps was has a very modular pipeline design when it comes to accessing the data. For example, consider getting the People for the flat view. First we get a cursor that iterates over the data. Then we sort it, on whatever criteria we have requested. To sort the data, not only do we need to iterate over all of the data, but we need to unpickle and turn the raw data into Person objects. Of course, it would be much faster if we can store the order in an indexFinally, so that we can just get filter the data that we need. This is even more important when we only want to see a filtered segment of the database, say those people who have a surname of "Smith."
In order to make this fastoperation faster for , we need to know the filter information, and sort order when we ask for the data. With SQL we can simply add WHERE clauses and ORDER BY clauses to the basic SELECT statement. But these are only useful if we can have indexes on the relevant data.
This is made more difficult because Gramps uses a hierarchical representation of data. For example, we might wish to have the People data sorted by "surname, given" of the primary_name. But that information is actually in:

Navigation menu