cqparts.catalogue package¶
Submodules¶
cqparts.catalogue.catalogue module¶
cqparts.catalogue.json module¶
-
class
cqparts.catalogue.json.JSONCatalogue(filename, clean=False)¶ Bases:
cqparts.catalogue.catalogue.CatalogueCatalogue with JSON storage using
tinydb.For more information, read Catalogue.
-
__init__(filename, clean=False)¶ Parameters: If a new database is created, a
_dbinfotable is added with version & module information to assist backward compatibility.
-
add(id, obj, criteria={}, force=False, _check_id=True)¶ Add a
Componentinstance to the database.Parameters: - id (
str) – unique id of entry, can be anything - obj (
Component) – component to be serialized, then added to the catalogue - criteria (
dict) – arbitrary search criteria for the entry - force (
bool) – ifTrue, entry is forcefully overwritten if it already exists. Otherwise an exception is raised - _check_id (
bool) – ifFalse, duplicateidis not tested
Raises: - TypeError – on parameter issues
- ValueError – if a duplicate db entry is detected (and
forceis not set)
Returns: index of new entry
Return type: - id (
-
close()¶ Close the database, and commit any changes to file.
-
dbinfo¶ Database information (at time of creation), mainly intended for future-proofing.
Returns: information about database’s initial creation Return type: dict
-
deserialize_item(data)¶ Create a
Componentfrom a database search result.Parameters: data ( dict) – result fromfind(), or an element ofsearch()Returns: deserialized object instance Return type: Component
-
find(*args, **kwargs)¶ Performs the same action as
search()but asserts a single result.Returns: Raises: - SearchNoneFoundError – if nothing was found
- SearchMultipleFoundError – if more than one result is found
-
get(*args, **kwargs)¶ Combination of
find()anddeserialize_item(); the result fromfind()is deserialized and returned.Input is a
tinydbquery.Returns: deserialized object instance Return type: Component
-
get_query()¶ Passthrough to return a
tinydb.Queryinstance. (mostly implemented so importingtinydbis not mandatory to search the catalogue)Returns: tinydbquery instanceReturn type: tinydb.Query
-
iter_items()¶ Iterate through all items in the catalogue
Returns: iterator for each item Return type: generator
-
search(*args, **kwargs)¶ Passthrough to
Table.search()for theitemstable.So
catalogue.search(...)equivalent tocatalogue.db.table('items').search(...).Returns: entries in itemstable that positively match given search criteria.Return type: listofitemstable entries
-
Module contents¶
-
class
cqparts.catalogue.Catalogue¶ Bases:
object-
iter_items()¶ Iterate through every item in the catalogue.
Returns: iterator for every item Return type: generator Note
Must be overridden by inheriting class
-
-
class
cqparts.catalogue.JSONCatalogue(filename, clean=False)¶ Bases:
cqparts.catalogue.catalogue.CatalogueCatalogue with JSON storage using
tinydb.For more information, read Catalogue.
-
__init__(filename, clean=False)¶ Parameters: If a new database is created, a
_dbinfotable is added with version & module information to assist backward compatibility.
-
add(id, obj, criteria={}, force=False, _check_id=True)¶ Add a
Componentinstance to the database.Parameters: - id (
str) – unique id of entry, can be anything - obj (
Component) – component to be serialized, then added to the catalogue - criteria (
dict) – arbitrary search criteria for the entry - force (
bool) – ifTrue, entry is forcefully overwritten if it already exists. Otherwise an exception is raised - _check_id (
bool) – ifFalse, duplicateidis not tested
Raises: - TypeError – on parameter issues
- ValueError – if a duplicate db entry is detected (and
forceis not set)
Returns: index of new entry
Return type: - id (
-
close()¶ Close the database, and commit any changes to file.
-
dbinfo¶ Database information (at time of creation), mainly intended for future-proofing.
Returns: information about database’s initial creation Return type: dict
-
deserialize_item(data)¶ Create a
Componentfrom a database search result.Parameters: data ( dict) – result fromfind(), or an element ofsearch()Returns: deserialized object instance Return type: Component
-
find(*args, **kwargs)¶ Performs the same action as
search()but asserts a single result.Returns: Raises: - SearchNoneFoundError – if nothing was found
- SearchMultipleFoundError – if more than one result is found
-
get(*args, **kwargs)¶ Combination of
find()anddeserialize_item(); the result fromfind()is deserialized and returned.Input is a
tinydbquery.Returns: deserialized object instance Return type: Component
-
get_query()¶ Passthrough to return a
tinydb.Queryinstance. (mostly implemented so importingtinydbis not mandatory to search the catalogue)Returns: tinydbquery instanceReturn type: tinydb.Query
-
iter_items()¶ Iterate through all items in the catalogue
Returns: iterator for each item Return type: generator
-
search(*args, **kwargs)¶ Passthrough to
Table.search()for theitemstable.So
catalogue.search(...)equivalent tocatalogue.db.table('items').search(...).Returns: entries in itemstable that positively match given search criteria.Return type: listofitemstable entries
-