Changes

Jump to: navigation, search

Using database API

2,780 bytes added, 15:20, 24 December 2009
no edit summary
GRAMPS is written in the [http://www.python.org Python] language. A basic familiarity with Python is required before the database objects can be effectively used. If you are new to Python, you may wish to check out the [http://docs.python.org/tut/tut.html Python tutorial].
 
== Database API ==
 
Access to the database is made through Python classes. Exactly what functionality you have is dependent on the properties of the database. For example, if you are accessing a read-only view, then you will only have access to a subset of the methods available.
 
At the root of any database interface is either DbReadBase and/or DbWriteBase. These define the methods to read and write to a database, respectively.
 
The full database hierarchy is:
 
* DbBsddb - read and write implementation to BSDDB databases ([http://gramps.svn.sourceforge.net/viewvc/gramps/trunk/src/gen/db/write.py?view=markup gen/db/write.py])
** DbWriteBase - virtual and implementation-independent methods for reading data ([http://gramps.svn.sourceforge.net/viewvc/gramps/trunk/src/gen/db/base.py?view=markup gen/db/base.py])
** DbBsddbRead - read-only (accessors, getters) implementation to BSDDB databases ([http://gramps.svn.sourceforge.net/viewvc/gramps/trunk/src/gen/db/read.py?view=markup gen/db/read.py])
*** DbReadBase - virtual and implementation-independent methods for reading data ([http://gramps.svn.sourceforge.net/viewvc/gramps/trunk/src/gen/db/base.py?view=markup gen/db/base.py])
* DbBDjango - read and write implementation to Django-based databases ([http://gramps.svn.sourceforge.net/viewvc/gramps/trunk/src/web/djangodb.py?view=markup web/djangodb.py])
** DbWriteBase - virtual and implementation-independent methods for reading data ([http://gramps.svn.sourceforge.net/viewvc/gramps/trunk/src/gen/db/base.py?view=markup gen/db/base.py])
** DbReadBase - virtual and implementation-independent methods for reading data ([http://gramps.svn.sourceforge.net/viewvc/gramps/trunk/src/gen/db/base.py?view=markup gen/db/base.py])
 
=== DbBsddb ===
 
The DbBsddb interface defines a hierarchical database (non-relational) and there is no such thing as a database schema. The meaning of the data is defined in the Python classes above. The data is stored as pickled tuples and unserialized into the primary data types (below).
 
=== DbDjango ===
 
The DbDjango interface defines the Gramps data in terms of ''models'' and ''relations'' from the [http://www.djangoproject.com/ Django project]. The database backend can be any implementation that supports Django, including such popular SQL implementations as sqlite, MySQL, Postgresql, and Oracle. The data is retrieved from the SQL fields, serialized and then unserialized into the primary data types (below).
 
=== Using the Database ===
 
For most cases, Gramps will have already opened a database for you. This is often embedded in a DbState object. Thus, you might interface the database like:
 
>>> dbstate.db.get_person_from_gramps_id("I0001")
 
However, to do any database activity, you need to understand the primary objects.
==Primary Objects==

Navigation menu