qldb_orm package¶
Subpackages¶
Submodules¶
qldb_orm.main module¶
- class qldb_orm.main.KeyValue(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)¶
Bases:
argparse.Action
Action class to map CLI input of the form key1=val1 key2=val2 … to an object’s properties.
- Parameters
argparse ([type]) – [description]
- qldb_orm.main.do_program(cli_args)¶
Entrypoint for the application.
- Parameters
cli_args (list) – command line arguments, i.e. sysv[1:]
- qldb_orm.main.entrypoint()¶
Entrypoint for build package
- qldb_orm.main.find(table, fields)¶
Find documents by field equality.
- Parameters
table (str) – Name of table to query
fields (kwargs) – key-value pairs of the fields
- Returns
collection of qldb_orm.qldb.Document
- Return type
list
- qldb_orm.main.get_all(table)¶
Find all documents in a table
- Parameters
table (str) – Name of table to be queried.
- Returns
collection of qldb_orm.qldb.Document
- Return type
list
- qldb_orm.main.history(table, id)¶
Query revision table history for particular metadata ID
- Parameters
table (str) – Table to be queried
id (str) – ID of the metadata revision
- Returns
collection of qldb_orm.qldb.Document
- Return type
list
- qldb_orm.main.insert(table, document)¶
Insert a document into a table
- Parameters
table (str) – Name of table to be queried.
document (
qldb_orm.qldb.Document
) – Document to be inserted
- Returns
id of the document inserted
- Return type
str
- qldb_orm.main.load(id, table)¶
Load a document from a table.
- Parameters
id (str) – ID of the document to load
table (str) – Name of table to be queried.
- Returns
collection of qldb_orm.qldb.Document
- Return type
- qldb_orm.main.mock(table)¶
Insert a mock document into a table
- Parameters
table (str) – Name of table to be queried.
- Returns
Document that was mocked
- Return type
- qldb_orm.main.print_line(n)¶
- qldb_orm.main.update_prop(document, **props)¶
Update properties on document and persist to QLDB
- Parameters
document (
qldb_orm.qldb.Document
) – Document to be updated- Returns
Updated document
- Return type
- qldb_orm.main.view_doc(document, unhide)¶
qldb_orm.qldb module¶
- class qldb_orm.qldb.Document(table, id=None, snapshot=None, ledger=None, stranded=False)¶
Bases:
qldb_orm.qldb.QLDB
A qldb_orm.qldb.Document object, representing an entry in an QLDB Ledger Table. Creates an instance of qldb_orm.qldb.Document. This object can be initialized in several states, depending on the parameters passed into the constructor.
Constructor Arguments: table
Constructor Arguments: table, id
Constructor Arguments: table, snapshot
In each case, an optional argument for ledger and stranded can be passed in.
- Parameters
table (str) – Name of the **QLDB**table
id (str, optional) – Id of the document to load, defaults to None
snapshot (dict, optional) – dict containing values to map to attributes, defaults to None
ledger (str, optional) – Name of the QLDB ledger, defaults to qldb_orm.settings.LEDGER
stranded – Flag to signal the document should initialized its history from the QLDB ledger
Note
If stranded==True, then the document history can be accessed through self.strands
- fields()¶
All of the qldb_orm.qldb.Document fields as a key-value dict. Hides the document attributes table, driver, index and ledger, if an object containing only the relevant fields.
- Returns
qldb_orm.qldb.Document fields
- Return type
dict
- save()¶
Save the current value of the qldb_orm.qldb.Document fields to the QLDB ledger table.
- class qldb_orm.qldb.QLDB(table, ledger=None)¶
Bases:
object
A class containing meta information associated with QLDB ledger.
- class qldb_orm.qldb.Query(table, ledger=None)¶
Bases:
qldb_orm.qldb.QLDB
Object that represents a PartiQL query. Get initialized on a particular table and ledger.
Methods will return results formatted as collections of qldb_orm.qldb.Document.
- find_by(**kwargs)¶
Filter qldb_orm.qldb.Document objects by the provided fields. This method accepts **kwargs arguments for the field name and values. The document fields must exactly match the fields provided in the query.
- Parameters
kwargs – Fields by which to filter the query.
- Returns
List of qldb_orm.qldb.Document
- Return type
list
- find_in(**kwargs)¶
Filter qldb_orm.qldb.Document objects by the provided fields. This method accepts **kwargs arguments for the field name and values, but the values must be an array.
The document fields must belong to the array associated with the field in the **kwargs. See below for example.
- Parameters
kwargs – Fields by which to filter the query.
- Returns
List of qldb_orm.qldb.Document
- Return type
list
Note
Example
`python Query('table').find_in(**{'field': [12, 13, 14], 'field2': ['cat', 'dog' ]}) `
will find all documents with a field whose value is in the set (12, 13, 14) and a field2 whose value is in the set (‘cat’, ‘dog’)
- get_all()¶
Return all qldb_orm.qldb.Document objects in the QLDB ledger table
- Returns
List of qldb_orm.qldb.Document
- Return type
list
- history(id=None)¶
Returns the revision history.
- Parameters
id (id of the document revision history , optional) – meta id, defaults to None
- Returns
a collection of qldb_orm.qldb.Document
- Return type
list
Note
id is not the index of the document. It is the metadata.id associated with the document across revisions. Query entire history to find a particular metadata.id
- raw(query)¶
Execute a raw query against the QLDB ledger.
- Parameters
query (str) – Query to be executed
- Returns
a collection of qldb_orm.qldb.Document
- Return type
list
Warning
Query will not be sanitized for injections.
qldb_orm.settings module¶
- qldb_orm.settings.get_log_level()¶
Return the current LOG_LEVEL in the settings as a string.
- Returns
The log level
- Return type
str