Databases

Databases are the places where parameter spaces live. You must use a database in DAPT and the Param class requires one to be provided. DAPT views databases similarly to a spreedsheet. Databases can be local or remote. If a database is local (e.g. Delimited file), then only one person can run the parameters. When a remote database (e.g. Google Sheets) is used, then multiple people can run the tests simultaneously.

Each database can contain several tables, which contain columns and rows. The tables of database hold a parameter space and each row is a parameter set. A column contains particular attributes within the space.

The databases provided in DAPT are all built off of the Base Database. This ensures that databases can be interchanged easily. For example, if you were using the Delimited file database, you could provide the Google Sheets to the Param class instead. This works because all databases must support the same core functions within the Base Database class. Some databases may have additional methods which work better with its design.

The only difference between these classes, from the user level, is the init and connect() methods. Database classes can be initialized using only a Config class. This makes it easy to swap between and initialize databases. Because some databases required users to login, you must connect to it before it can be accessed. This should be done before trying to access the data.

Usage

Because the usage for each database is almost identical, it will be explained here instead of in the submodules. More explications on the methods, checkout the Base Database. The connection steps for each database will be explained within the respective documentation.

For this example, the Sample database will be used. By calling the sample_db() method, an example Delimited file class is created.

>>> db = dapt.tools.sample_db(file_name='sample_db.csv', delimiter=',')

This method returns an instance of the database, but the line below shows how a new database instance can be created.

>>> db = dapt.db.Delimited_file(path='sample_db.csv', delimiter=',')

The Delimited file class doesn’t need to connect to anything, but most databases will so you should always run connect().

>>> db.connect()
True

The table can simply be viewed by running:

>>> db.get_table()
[{'id': 't1', 'start-time': '2019-09-06 17:23', 'end-time': '2019-09-06 17:36',
  'status': 'finished', 'a': '2', 'b': '4', 'c': '6'},
{'id': 't2', 'start-time': '', 'end-time': '', 'status': '', 'a': '10', 'b': '10', 'c': ''},
{'id': 't3', 'start-time': '', 'end-time': '', 'status': '', 'a': '10', 'b': '-10', 'c': ''}]

Tables are represented as an array of dictionaries. Each element is a parameter set. The keys in the dictionary are attributes and values are specific cells in the table.