mirror of
https://github.com/pyMC-dev/pyMC_Repeater.git
synced 2026-08-07 01:13:11 +02:00
Add JSON serialization support for companion preferences
- Introduced a new utility function, _to_json_safe, to ensure companion preferences are JSON-serializable, handling various data types including enums and dataclasses. - Updated the RepeaterCompanionBridge to use the new serialization method when saving preferences to SQLite. - Modified SQLiteHandler to ensure companion_hash is consistently converted to a string before database operations. - Enhanced error handling for preference persistence in the RepeaterCompanionBridge.
This commit is contained in:
@@ -1833,6 +1833,7 @@ class SQLiteHandler:
|
||||
"""Persist prefs for a companion as JSON. Upserts by companion_hash."""
|
||||
try:
|
||||
prefs_json = json.dumps(prefs)
|
||||
key = str(companion_hash) if companion_hash is not None else ""
|
||||
with sqlite3.connect(self.sqlite_path) as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
@@ -1840,7 +1841,7 @@ class SQLiteHandler:
|
||||
VALUES (?, ?)
|
||||
ON CONFLICT(companion_hash) DO UPDATE SET prefs_json = excluded.prefs_json
|
||||
""",
|
||||
(companion_hash, prefs_json),
|
||||
(key, prefs_json),
|
||||
)
|
||||
conn.commit()
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user