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
key : str or list of str or None, optional (default=None)
timeout : float, optional (default=7200.0)
|
---|---|
Returns: | out : dict
|
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