Changes

Jump to: navigation, search

Using database API

396 bytes added, 21:15, 16 July 2021
m
grammar
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 [httphttps://www.gramps-project.org/docs/ 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 DataModel]] overview are available.
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 [https://docs.python.org/2/tutorial/ Python 2.x tutorial] or [https://docs.python.org/3/tutorial/ Python 3.x tutorial].
** '''UpdateCallback''' - callback functionality ([http://sourceforge.net/p/gramps/source/ci/master/tree/gramps/gen/updatecallback.py gen/updatecallback.py])
** '''DbTxn''' - class for managing Gramps transactions and the undo database ([http://sourceforge.net/p/gramps/source/ci/master/tree/gramps/gen/db/txn.py gen/db/txn.py])
* '''DbDjangoDbGeneric''' - general read and write implementation to Django-based databases ([http://sourceforge.net/p/gramps/source/ci/master/tree/gramps/webapp/dbdjango.py webapp/dbdjango.py])implementations
** '''DbWriteBase''' - virtual and implementation-independent methods for reading data ([http://sourceforge.net/p/gramps/source/ci/master/tree/gramps/gen/db/base.py gen/db/base.py])
** '''DbReadBase''' - virtual and implementation-independent methods for reading data ([http://sourceforge.net/p/gramps/source/ci/master/tree/gramps/gen/db//base.py gen/db/base.py])
The DbBsddb interface defines a hierarchical database (non-relational) written in [http://www.jcea.es/programacion/pybsddb.htm 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)]].
=== DbDjango DB-API ===
The DbDjango DB-API interface defines the Gramps data in terms of ''models'' and ''relations'' from uses a generic interface backed with the general Python SQL implementation, called [httphttps://www.djangoprojectpython.comorg/dev/peps/ Django projectpep-0249/ DB-API]. The Gramps' generic interface (gramps.gen.db.generic.DbGeneric) has all of the logic for interacting with the database backend can be any implementation that supports Django, including such popular 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 implementations as sqlite, MySQL, Postgresql, and Oracledatabases. The data is retrieved from Other database engines could also implement the SQL fieldsDbGeneric details, serialized and then unserialized into the primary data types (below)such as a nosql option.
For more details on the By default, Gramps Django projectDB-API uses sqlite. However, see [[GEPS 013: you can also configure DB-API to use mysql, postgresql, and perhaps others. To be compatible with BSDDB, DB-API stores Gramps Webapp]]data 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, initialize objects, and compare properties.
=== Using the Database ===
person1.set_nickname('Fred')
</pre>
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.
database.connect('person-update',self.update_view)
database.connect('person-rebuild',self.update_view)
A full list of the signals that are emitted from the database can be found at the top of the <tt>[https://gramps-project.org/docs/gen/gen_db.html#module-gramps.gen.db.base GrampsDbBase]</tt> class in the <tt>[httphttps://sourceforgegithub.netcom/pgramps-project/gramps/source/ciblob/master/tree/gramps/gen/db/base.py gramps/gen/db/base.py]</tt> module.
[[Category:Developers/Tutorials]]

Navigation menu