18
18
19
19
20
20
class SqliteBoardRecordStorage (BoardRecordStorageBase ):
21
- _conn : sqlite3 .Connection
22
- _cursor : sqlite3 .Cursor
23
-
24
21
def __init__ (self , db : SqliteDatabase ) -> None :
25
22
super ().__init__ ()
26
23
self ._conn = db .conn
27
- self ._cursor = self ._conn .cursor ()
28
24
29
25
def delete (self , board_id : str ) -> None :
30
26
try :
31
- self ._cursor .execute (
27
+ cursor = self ._conn .cursor ()
28
+ cursor .execute (
32
29
"""--sql
33
30
DELETE FROM boards
34
31
WHERE board_id = ?;
@@ -46,7 +43,8 @@ def save(
46
43
) -> BoardRecord :
47
44
try :
48
45
board_id = uuid_string ()
49
- self ._cursor .execute (
46
+ cursor = self ._conn .cursor ()
47
+ cursor .execute (
50
48
"""--sql
51
49
INSERT OR IGNORE INTO boards (board_id, board_name)
52
50
VALUES (?, ?);
@@ -64,7 +62,8 @@ def get(
64
62
board_id : str ,
65
63
) -> BoardRecord :
66
64
try :
67
- self ._cursor .execute (
65
+ cursor = self ._conn .cursor ()
66
+ cursor .execute (
68
67
"""--sql
69
68
SELECT *
70
69
FROM boards
@@ -73,7 +72,7 @@ def get(
73
72
(board_id ,),
74
73
)
75
74
76
- result = cast (Union [sqlite3 .Row , None ], self . _cursor .fetchone ())
75
+ result = cast (Union [sqlite3 .Row , None ], cursor .fetchone ())
77
76
except sqlite3 .Error as e :
78
77
raise BoardRecordNotFoundException from e
79
78
if result is None :
@@ -86,9 +85,10 @@ def update(
86
85
changes : BoardChanges ,
87
86
) -> BoardRecord :
88
87
try :
88
+ cursor = self ._conn .cursor ()
89
89
# Change the name of a board
90
90
if changes .board_name is not None :
91
- self . _cursor .execute (
91
+ cursor .execute (
92
92
"""--sql
93
93
UPDATE boards
94
94
SET board_name = ?
@@ -99,7 +99,7 @@ def update(
99
99
100
100
# Change the cover image of a board
101
101
if changes .cover_image_name is not None :
102
- self . _cursor .execute (
102
+ cursor .execute (
103
103
"""--sql
104
104
UPDATE boards
105
105
SET cover_image_name = ?
@@ -110,7 +110,7 @@ def update(
110
110
111
111
# Change the archived status of a board
112
112
if changes .archived is not None :
113
- self . _cursor .execute (
113
+ cursor .execute (
114
114
"""--sql
115
115
UPDATE boards
116
116
SET archived = ?
@@ -133,6 +133,8 @@ def get_many(
133
133
limit : int = 10 ,
134
134
include_archived : bool = False ,
135
135
) -> OffsetPaginatedResults [BoardRecord ]:
136
+ cursor = self ._conn .cursor ()
137
+
136
138
# Build base query
137
139
base_query = """
138
140
SELECT *
@@ -150,9 +152,9 @@ def get_many(
150
152
)
151
153
152
154
# Execute query to fetch boards
153
- self . _cursor .execute (final_query , (limit , offset ))
155
+ cursor .execute (final_query , (limit , offset ))
154
156
155
- result = cast (list [sqlite3 .Row ], self . _cursor .fetchall ())
157
+ result = cast (list [sqlite3 .Row ], cursor .fetchall ())
156
158
boards = [deserialize_board_record (dict (r )) for r in result ]
157
159
158
160
# Determine count query
@@ -169,15 +171,16 @@ def get_many(
169
171
"""
170
172
171
173
# Execute count query
172
- self . _cursor .execute (count_query )
174
+ cursor .execute (count_query )
173
175
174
- count = cast (int , self . _cursor .fetchone ()[0 ])
176
+ count = cast (int , cursor .fetchone ()[0 ])
175
177
176
178
return OffsetPaginatedResults [BoardRecord ](items = boards , offset = offset , limit = limit , total = count )
177
179
178
180
def get_all (
179
181
self , order_by : BoardRecordOrderBy , direction : SQLiteDirection , include_archived : bool = False
180
182
) -> list [BoardRecord ]:
183
+ cursor = self ._conn .cursor ()
181
184
if order_by == BoardRecordOrderBy .Name :
182
185
base_query = """
183
186
SELECT *
@@ -199,9 +202,9 @@ def get_all(
199
202
archived_filter = archived_filter , order_by = order_by .value , direction = direction .value
200
203
)
201
204
202
- self . _cursor .execute (final_query )
205
+ cursor .execute (final_query )
203
206
204
- result = cast (list [sqlite3 .Row ], self . _cursor .fetchall ())
207
+ result = cast (list [sqlite3 .Row ], cursor .fetchall ())
205
208
boards = [deserialize_board_record (dict (r )) for r in result ]
206
209
207
210
return boards
0 commit comments