yawning_titan.db.yawning_titan_db.YawningTitanDB#
- class yawning_titan.db.yawning_titan_db.YawningTitanDB(name, root=None)[source]#
Bases:
object
An
ABC
that implements and extends theTinyDB
query functions.Methods
A wrapper for
tinydb.table.Table.all()
.Close the db.
Count how many docs are in the db.
Get a doc from its uuid.
An extension of
tinydb.table.Table.insert()
.Check whether a doc is locked for editing or not.
Remove a document with a given _doc_metadata.uuid.
Remove documents that match a query.
A wrapper for
tinydb.table.Table.search()
.Show details of all entries in the db.
An extension of
tinydb.table.Table.update()
.A manual upsert method in place of
tinydb.table.Table.upsert()
.Attributes
- classmethod is_locked(doc)[source]#
Check whether a doc is locked for editing or not.
- Parameters:
doc – A doc.
- Returns:
True
if the doc is locked, otherwiseFalse
.
- property name#
The DB name.
- count(cond=None)[source]#
Count how many docs are in the db. Extends
tinydb.table.Table.count
.A
YawningTitanQuery
can be used to filter the count.- Parameters:
cond – An optional
YawningTitanQuery
. Has a default value ofNone
.- Returns:
The number of docs counted.
- show(verbose=False)[source]#
Show details of all entries in the db.
- Parameters:
verbose – If True, all doc metadata details are shown, otherwise just the name is shown.
- get(uuid)[source]#
Get a doc from its uuid.
- Parameters:
uuid – A uuid.
- Returns:
The matching doc if it exists, otherwise
None
.- Raise:
YawningTitanDBCriticalError
when the search returns multiple docs with the same uuid.
- insert(doc, name=None, description=None, author=None)[source]#
An extension of
tinydb.table.Table.insert()
.If a doc doesn’t have DocMetadata, the default DocMetadata is set.
If a doc already exists with the same uuid, the insert is blocked and a
YawningTitanDBCriticalError
is raised alongside a log asCRITICAL
level, as this would indicate db file is corrupted.- Parameters:
doc – A doc.
name – The doc name.
description – The doc description.
author – The docs author.
- Returns:
The inserted doc.
- Raise:
YawningTitanDBCriticalError
when a doc already exists with the same uuid.
- update(doc, uuid, name=None, description=None, author=None)[source]#
An extension of
tinydb.table.Table.update()
.Performs a check that prevents locked files from being updated and raises
YawningTitanDBError
alongside a log atINFO
level.- Parameters:
doc – A doc.
uuid – The docs uuid.
name – The doc name.
description – The doc description.
author – The docs author.
- Returns:
The updated doc.
- Raise:
YawningTitanDBError
if the doc is locked.
- upsert(doc, uuid, name=None, description=None, author=None)[source]#
A manual upsert method in place of
tinydb.table.Table.upsert()
.If the docs uuid already exists, the args are passed to
yawning_titan.db.yawning_titan_db.YawningTitanDB.update()
to perform an update, otherwise they’re passed toinsert()
to perform an insert. This is done to make use of the existing uuid and locked file handling in the two methods.- Parameters:
doc – A doc.
uuid – The docs uuid.
name – The doc name.
description – The doc description.
author – The docs author.
- Returns:
The updated doc.
- remove_by_cond(cond)[source]#
Remove documents that match a query.
- Parameters:
cond – A:class:~yawning_titan.db.query.YawningTitanQuery.
- Returns:
The list of uuids from documents removed.
- remove(uuid)[source]#
Remove a document with a given _doc_metadata.uuid.
- Parameters:
uuid – A documents _doc_metadata.uuid.
- Returns:
The uuid of the removed document.
- Raises:
YawningTitanDBCriticalError
when there is more than one doc with the same uuid to remove.YawningTitanDBError
when an attempt to remove a locked doc is made.