clusterlib.storage.sqlite3_loads

clusterlib.storage.sqlite3_loads(file_name, key=None, timeout=7200.0)

Load value with key from sqlite3 stored at fname

In order to improve performance, it’s advised to query the database using a (small) list of keys. Otherwise by calling this functions repeatedly, you might run into the SQlite lock timeout.

Parameters:

file_name : str

Path to the sqlite database.

key : str or list of str or None, optional (default=None)

Key used when the value was stored or list of keys. If None, all key, value pair from the database are returned.

timeout : float, optional (default=7200.0)

The timeout parameter specifies how long the connection should wait for the lock to go away until raising an exception.

Returns:

out : dict

Return a dict where each key point is associated to the stored object. If a key from key is missing in the sqlite3, then there is no entry in out for this key. If there is no sqlite3 database at file_name, then an empty dictionary is returned.

Examples

Here, we generate a temporary sqlite3 database, dump then load some data from it.

>>> from tempfile import NamedTemporaryFile
>>> from clusterlib.storage import sqlite3_dumps
>>> from clusterlib.storage import sqlite3_loads
>>> with NamedTemporaryFile() as fhandle:
...     sqlite3_dumps({"3": 3, "2": 5}, fhandle.name)
...     out = sqlite3_loads(fhandle.name, key=["7", "3"])
...     print(out['3'])
...     print("7" in out)  # "7" is not in the database
3
False

It’s also possible to get all key-value pairs from the database without specifying the keys.

>>> with NamedTemporaryFile() as fhandle:
...     sqlite3_dumps({'first': 1}, fhandle.name)
...     out = sqlite3_loads(fhandle.name)
...     print(out['first'])
1