@@ -18,31 +18,32 @@ class SqliteStylePresetRecordsStorage(StylePresetRecordsStorageBase):
18
18
def __init__ (self , db : SqliteDatabase ) -> None :
19
19
super ().__init__ ()
20
20
self ._conn = db .conn
21
- self ._cursor = self ._conn .cursor ()
22
21
23
22
def start (self , invoker : Invoker ) -> None :
24
23
self ._invoker = invoker
25
24
self ._sync_default_style_presets ()
26
25
27
26
def get (self , style_preset_id : str ) -> StylePresetRecordDTO :
28
27
"""Gets a style preset by ID."""
29
- self ._cursor .execute (
28
+ cursor = self ._conn .cursor ()
29
+ cursor .execute (
30
30
"""--sql
31
31
SELECT *
32
32
FROM style_presets
33
33
WHERE id = ?;
34
34
""" ,
35
35
(style_preset_id ,),
36
36
)
37
- row = self . _cursor .fetchone ()
37
+ row = cursor .fetchone ()
38
38
if row is None :
39
39
raise StylePresetNotFoundError (f"Style preset with id { style_preset_id } not found" )
40
40
return StylePresetRecordDTO .from_dict (dict (row ))
41
41
42
42
def create (self , style_preset : StylePresetWithoutId ) -> StylePresetRecordDTO :
43
43
style_preset_id = uuid_string ()
44
44
try :
45
- self ._cursor .execute (
45
+ cursor = self ._conn .cursor ()
46
+ cursor .execute (
46
47
"""--sql
47
48
INSERT OR IGNORE INTO style_presets (
48
49
id,
@@ -68,10 +69,11 @@ def create(self, style_preset: StylePresetWithoutId) -> StylePresetRecordDTO:
68
69
def create_many (self , style_presets : list [StylePresetWithoutId ]) -> None :
69
70
style_preset_ids = []
70
71
try :
72
+ cursor = self ._conn .cursor ()
71
73
for style_preset in style_presets :
72
74
style_preset_id = uuid_string ()
73
75
style_preset_ids .append (style_preset_id )
74
- self . _cursor .execute (
76
+ cursor .execute (
75
77
"""--sql
76
78
INSERT OR IGNORE INTO style_presets (
77
79
id,
@@ -97,9 +99,10 @@ def create_many(self, style_presets: list[StylePresetWithoutId]) -> None:
97
99
98
100
def update (self , style_preset_id : str , changes : StylePresetChanges ) -> StylePresetRecordDTO :
99
101
try :
102
+ cursor = self ._conn .cursor ()
100
103
# Change the name of a style preset
101
104
if changes .name is not None :
102
- self . _cursor .execute (
105
+ cursor .execute (
103
106
"""--sql
104
107
UPDATE style_presets
105
108
SET name = ?
@@ -110,7 +113,7 @@ def update(self, style_preset_id: str, changes: StylePresetChanges) -> StylePres
110
113
111
114
# Change the preset data for a style preset
112
115
if changes .preset_data is not None :
113
- self . _cursor .execute (
116
+ cursor .execute (
114
117
"""--sql
115
118
UPDATE style_presets
116
119
SET preset_data = ?
@@ -127,7 +130,8 @@ def update(self, style_preset_id: str, changes: StylePresetChanges) -> StylePres
127
130
128
131
def delete (self , style_preset_id : str ) -> None :
129
132
try :
130
- self ._cursor .execute (
133
+ cursor = self ._conn .cursor ()
134
+ cursor .execute (
131
135
"""--sql
132
136
DELETE from style_presets
133
137
WHERE id = ?;
@@ -152,12 +156,13 @@ def get_many(self, type: PresetType | None = None) -> list[StylePresetRecordDTO]
152
156
153
157
main_query += "ORDER BY LOWER(name) ASC"
154
158
159
+ cursor = self ._conn .cursor ()
155
160
if type is not None :
156
- self . _cursor .execute (main_query , (type ,))
161
+ cursor .execute (main_query , (type ,))
157
162
else :
158
- self . _cursor .execute (main_query )
163
+ cursor .execute (main_query )
159
164
160
- rows = self . _cursor .fetchall ()
165
+ rows = cursor .fetchall ()
161
166
style_presets = [StylePresetRecordDTO .from_dict (dict (row )) for row in rows ]
162
167
163
168
return style_presets
@@ -167,7 +172,8 @@ def _sync_default_style_presets(self) -> None:
167
172
168
173
# First delete all existing default style presets
169
174
try :
170
- self ._cursor .execute (
175
+ cursor = self ._conn .cursor ()
176
+ cursor .execute (
171
177
"""--sql
172
178
DELETE FROM style_presets
173
179
WHERE type = "default";
0 commit comments