Bob Database Support¶
Todo
Improve the documentation by providing a users guide and a development guide.
(The original entry is located in /home/travis/build/bioidiap/bob.db.base/doc/index.rst, line 13.)
Todo
Improve the documentation by providing a users guide and a development guide.
Bob provides an API to easily query and interface with well known database protocols. A Bob database contains information about the organization of the files, functions to query information such as the data which might be used for training a model, but it usually does not contain the data itself (except for some toy examples). Many of the database packages provide functionality through data stored in sqlite files, whereas the smallest ones can be stored as filelists.
As databases usually contain thousands of files, and as verification protocols often require to store information about pairs of files, the size of such databases can become very large. For this reason, we have decided to externalize many of them in Satellite Packages.
Reference¶
This section contains the reference guide for bob.db.base
.
The db package contains simplified APIs to access data for various databases that can be used in Biometry, Machine Learning or Pattern Classification.
Database Handling Utilities¶
Some utilities shared by many of the databases.
-
bob.db.base.utils.
apsw_is_available
()[source]¶ Checks lock-ability for SQLite on the current file system
-
class
bob.db.base.utils.
SQLiteConnector
(filename, readonly=False, lock=None)[source]¶ Bases:
object
An object that handles the connection to SQLite databases.
Initializes the connector
Keyword arguments
- filename
- The name of the file containing the SQLite database
- readonly
- Should I try and open the database in read-only mode?
- lock
- Any vfs name as output by apsw.vfsnames()
-
APSW_IS_AVAILABLE
= False¶
-
bob.db.base.utils.
session
(dbtype, dbfile, echo=False)[source]¶ Creates a session to an SQLite database
-
bob.db.base.utils.
session_try_readonly
(dbtype, dbfile, echo=False)[source]¶ Creates a read-only session to an SQLite database. If read-only sessions are not supported by the underlying sqlite3 python DB driver, then a normal session is returned. A warning is emitted in case the underlying filesystem does not support locking properly.
Raises a NotImplementedError if the dbtype is not supported.
-
bob.db.base.utils.
create_engine_try_nolock
(dbtype, dbfile, echo=False)[source]¶ Creates an engine connected to an SQLite database with no locks. If engines without locks are not supported by the underlying sqlite3 python DB driver, then a normal engine is returned. A warning is emitted if the underlying filesystem does not support locking properly in this case.
Raises a NotImplementedError if the dbtype is not supported.
-
bob.db.base.utils.
session_try_nolock
(dbtype, dbfile, echo=False)[source]¶ Creates a session to an SQLite database with no locks. If sessions without locks are not supported by the underlying sqlite3 python DB driver, then a normal session is returned. A warning is emitted if the underlying filesystem does not support locking properly in this case.
Raises a NotImplementedError if the dbtype is not supported.
Driver API¶
This module defines, among other less important constructions, a management interface that can be used by Bob to display information about the database and manage installed files.
-
class
bob.db.base.driver.
Interface
[source]¶ Bases:
abc.NewBase
Base manager for Bob databases
-
files
()[source]¶ Returns a python iterable with all auxiliary files needed.
The values should be take w.r.t. where the python file that declares the database is sitting at.
-
type
()[source]¶ Returns the type of auxiliary files you have for this database
If you return ‘sqlite’, then we append special actions such as ‘dbshell’ on ‘bob_dbmanage.py’ automatically for you. Otherwise, we don’t.
If you use auxiliary text files, just return ‘text’. We may provide special services for those types in the future.
Use the special name ‘builtin’ if this database is an integral part of Bob.
-
setup_parser
(parser, short_description, long_description)[source]¶ Sets up the base parser for this database.
Keyword arguments:
- short_description
- A short description (one-liner) for this database
- long_description
- A more involved explanation of this database
Returns a subparser, ready to be added commands on
-
add_commands
(parser)[source]¶ Adds commands to a given (
argparse
) parser.This method, effectively, allows you to define special commands that your database will be able to perform when called from the common driver like for example
create
orcheckfiles
.You are not obliged to overwrite this method. If you do, you will have the chance to establish your own commands. You don’t have to worry about stock commands such as
files()
orversion()
. They will be automatically hooked-in depending on the values you return fortype()
andfiles()
.Keyword arguments
- parser
- An instance of a
argparse.ArgumentParser
that you can customize, i.e., callargparse.ArgumentParser.add_argument()
on.
-