Jump to: navigation, search

Using database API

674 bytes added, 21:15, 16 July 2021
{{man warn|If you are a looking for documentation on how to use the Gramps system as a user instead of as a program developer, it can be found on the [[Portal:Using_Gramps|Gramps documentation web page]].}}
Explanation of the basics, underlying Gramps database. '''This is not intended to be a reference manual''', but an introductory programmer's guide to using the Gramps database access routines.
Separate [http API Reference Documentation for current version 4.0.x of Gramps] and as well as a simple [[Media:API.svg|UML (svg) diagram for 4.1.x]] and [[Gramps Data Model]] overview are available.
Gramps is written in the [ 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 [ Python 2.x tutorial] or [ Python 3.x tutorial].
** '''DbBsddbRead''' - read-only (accessors, getters) implementation to BSDDB databases ([ gen/db/])
*** '''DbReadBase''' - virtual and implementation-independent methods for reading data ([ gen/db/])
*** '''Callback''' - callback and signal functions ([ gen/utils/])** '''UpdateCallback''' - callback functionality ([ gen/])** '''DbTxn''' - class for managing Gramps transactions and the undo database ([ gen/db/])* '''DbDjangoDbGeneric''' - general read and write implementation to Django-based databases ([ webapp/])implementations** '''DbWriteBase''' - virtual and implementation-independent methods for reading data ([ gen/db/])
** '''DbReadBase''' - virtual and implementation-independent methods for reading data ([ gen/db/])
=== DbBsddb ===
The DbBsddb interface defines a hierarchical database (non-relational) written in [ PyBSDDB]. There is no such thing as a database schema, and the meaning of the data is defined in the Python classes above. The data is stored as pickled tuples and unserialized into the [[Using_database_API#Primary_Objects|primary data types (below)]]=== DB-API ===
=== DbDjango ===The DB-API interface uses a generic interface backed with the general Python SQL implementation, called [ DB-API]. The Gramps' generic interface (gramps.gen.db.generic.DbGeneric) has all of the logic for interacting with the database, except for the specific DB access code. Gramps' DB-API (gramps.plugins.db.dbapi.dbapi) implements the details so as to talk to conforming SQL databases. Other database engines could also implement the DbGeneric details, such as a nosql option.
The DbDjango interface defines the By default, Gramps data in terms of ''models'' and ''relations'' from the [http://wwwDB-API uses Django project]. The database backend However, you can be any implementation that supports Django, including such popular SQL implementations as sqlite, MySQL, Postgresqlalso configure DB-API to use mysql, and Oracle. The data is retrieved from the SQL fieldspostgresql, serialized and then unserialized into the primary data types (below)perhaps others.
For more details on the To be compatible with BSDDB, DB-API stores Gramps Django projectdata in an identical manner (pickled tuples). However, to allow for fast access, DB-API also stores "flat" data (such as strings and integers) in secondary SQL fields. These are indexed so that data can be selected without having to traverse, unpickle, see [[GEPS 013: Gramps Webapp]]initialize objects, and compare properties.
=== Using the Database ===
For this reason, it is always necessary to have reference to the database that contains the objects with which you are working.
The handle should not be visible to the end user, and should not be included in reports or displayed on screen. Instead, the GRAMPS Gramps ID value should be used for this purpose. The GRAMPS Gramps ID is a user defined value for each object, but is not used internally to the database. This allows the user to change the GRAMPS Gramps ID without affecting the database.
Once created, the handle should never be modified.
In this case, even though person1 and person2 represent the same person, but they are distinct objects. Changing the nickname of person1 does not affect person2. The person2 object will retain the original nickname.
Changes to the object do not become permanent until the object has been committed to the database. If multiple instances exist in memory at the same time, care must be taken to make sure that data is not lost.
A full list of the signals that are emitted from the database can be found at the top of the <tt>[ GrampsDbBase]</tt> class in the <tt>GrampsDbBase[ gramps/gen/db/]</tt> module.

Navigation menu