cqparts.catalogue package¶
Submodules¶
cqparts.catalogue.catalogue module¶
cqparts.catalogue.json module¶
-
class
cqparts.catalogue.json.
JSONCatalogue
(filename, clean=False)¶ Bases:
cqparts.catalogue.catalogue.Catalogue
Catalogue with JSON storage using
tinydb
.For more information, read Catalogue.
-
__init__
(filename, clean=False)¶ Parameters: If a new database is created, a
_dbinfo
table is added with version & module information to assist backward compatibility.
-
add
(id, obj, criteria={}, force=False, _check_id=True)¶ Add a
Component
instance 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
, duplicateid
is not tested
Raises: - TypeError – on parameter issues
- ValueError – if a duplicate db entry is detected (and
force
is 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
Component
from 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
tinydb
query.Returns: deserialized object instance Return type: Component
-
get_query
()¶ Passthrough to return a
tinydb.Query
instance. (mostly implemented so importingtinydb
is not mandatory to search the catalogue)Returns: tinydb
query 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 theitems
table.So
catalogue.search(...)
equivalent tocatalogue.db.table('items').search(...)
.Returns: entries in items
table that positively match given search criteria.Return type: list
ofitems
table 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.Catalogue
Catalogue with JSON storage using
tinydb
.For more information, read Catalogue.
-
__init__
(filename, clean=False)¶ Parameters: If a new database is created, a
_dbinfo
table is added with version & module information to assist backward compatibility.
-
add
(id, obj, criteria={}, force=False, _check_id=True)¶ Add a
Component
instance 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
, duplicateid
is not tested
Raises: - TypeError – on parameter issues
- ValueError – if a duplicate db entry is detected (and
force
is 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
Component
from 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
tinydb
query.Returns: deserialized object instance Return type: Component
-
get_query
()¶ Passthrough to return a
tinydb.Query
instance. (mostly implemented so importingtinydb
is not mandatory to search the catalogue)Returns: tinydb
query 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 theitems
table.So
catalogue.search(...)
equivalent tocatalogue.db.table('items').search(...)
.Returns: entries in items
table that positively match given search criteria.Return type: list
ofitems
table entries
-