mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00

Needed to add a Filter possibility to facilitate that Created a Simple UserString class which can be used as: ```py sql_filter = SQLFilter(f"SELECT {{}} FROM table_name WHERE id = ?") cursor.execute(sql_filter) # Will execute: SELECT * FROM table_name WHERE id = ? cursor.execute(sql_filter["id", "name"]) # Will execute: SELECT id, name FROM table_name WHERE id = ? ``` Contributes to CURA-6096
32 lines
1.6 KiB
Python
32 lines
1.6 KiB
Python
from UM.Settings.SQLQueryFactory import SQLQueryFactory, metadata_type
|
|
from UM.Settings.DatabaseContainerMetadataController import DatabaseMetadataContainerController
|
|
|
|
|
|
class QualityDatabaseHandler(DatabaseMetadataContainerController):
|
|
"""The Database handler for Quality containers"""
|
|
|
|
def __init__(self):
|
|
super().__init__(SQLQueryFactory(table = "qualities",
|
|
fields = {
|
|
"name": "text",
|
|
"quality_type": "text",
|
|
"material": "text",
|
|
"variant": "text",
|
|
"global_quality": "bool",
|
|
"definition": "text",
|
|
"version": "text",
|
|
"setting_version": "text"
|
|
}))
|
|
|
|
def groomMetadata(self, metadata: metadata_type) -> metadata_type:
|
|
"""
|
|
Ensures that the metadata is in the order of the field keys and has the right size.
|
|
if the metadata doesn't contains a key which is stored in the DB it will add it as
|
|
an empty string. Key, value pairs that are not stored in the DB are dropped.
|
|
If the `global_quality` isn't set it well default to 'False'
|
|
|
|
:param metadata: The container metadata
|
|
"""
|
|
if "global_quality" not in metadata:
|
|
metadata["global_quality"] = "False"
|
|
return super().groomMetadata(metadata)
|