Skip to content

Commit eb290cb

Browse files
rename some troublesome methods related to internal datastores and improve overall doc coverage of streamableresource.py
1 parent c79d5d2 commit eb290cb

4 files changed

Lines changed: 439 additions & 68 deletions

File tree

src/oshconnect/datastores/sqlite_store.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class SQLiteDataStore(DataStore):
3030
Schema notes
3131
------------
3232
Each resource type is stored as a single JSON blob (the output of its
33-
``serialize()`` method) alongside a primary-key string ID and any foreign-key
34-
columns needed for filtered lookups. Using blobs means new Pydantic fields
35-
do not require schema migrations.
33+
``to_storage_dict()`` method) alongside a primary-key string ID and any
34+
foreign-key columns needed for filtered lookups. Using blobs means new
35+
Pydantic fields do not require schema migrations.
3636
3737
*Bulk operations* (``save_all`` / ``load_all``) work at the Node level:
3838
``save_all`` persists every resource separately for individual lookups;
3939
``load_all`` reconstructs the full hierarchy from the *nodes* table only
40-
(``Node.deserialize`` handles the embedded systems/streams), avoiding
40+
(``Node.from_storage_dict`` handles the embedded systems/streams), avoiding
4141
duplication.
4242
"""
4343

@@ -87,7 +87,7 @@ def _execute(self, sql: str, params: tuple = ()) -> sqlite3.Cursor:
8787
# ------------------------------------------------------------------
8888

8989
def save_node(self, node: Node) -> None:
90-
data = json.dumps(node.serialize())
90+
data = json.dumps(node.to_storage_dict())
9191
self._execute(
9292
"INSERT OR REPLACE INTO nodes (id, data) VALUES (?, ?)",
9393
(node.get_id(), data),
@@ -102,14 +102,14 @@ def load_node(
102102
).fetchone()
103103
if row is None:
104104
return None
105-
return Node.deserialize(json.loads(row["data"]), session_manager=session_manager)
105+
return Node.from_storage_dict(json.loads(row["data"]), session_manager=session_manager)
106106

107107
def load_all_nodes(
108108
self, session_manager: Optional[SessionManager] = None
109109
) -> list[Node]:
110110
rows = self._execute("SELECT data FROM nodes").fetchall()
111111
return [
112-
Node.deserialize(json.loads(r["data"]), session_manager=session_manager)
112+
Node.from_storage_dict(json.loads(r["data"]), session_manager=session_manager)
113113
for r in rows
114114
]
115115

@@ -123,7 +123,7 @@ def delete_node(self, node_id: str) -> None:
123123

124124
def save_system(self, system: System, node: Node) -> None:
125125
system_id = str(system.get_internal_id())
126-
data = json.dumps(system.serialize())
126+
data = json.dumps(system.to_storage_dict())
127127
self._execute(
128128
"INSERT OR REPLACE INTO systems (id, node_id, data) VALUES (?, ?, ?)",
129129
(system_id, node.get_id(), data),
@@ -136,13 +136,13 @@ def load_system(self, system_id: str, node: Node) -> Optional[System]:
136136
).fetchone()
137137
if row is None:
138138
return None
139-
return System.deserialize(json.loads(row["data"]), node)
139+
return System.from_storage_dict(json.loads(row["data"]), node)
140140

141141
def load_systems_for_node(self, node_id: str, node: Node) -> list[System]:
142142
rows = self._execute(
143143
"SELECT data FROM systems WHERE node_id = ?", (node_id,)
144144
).fetchall()
145-
return [System.deserialize(json.loads(r["data"]), node) for r in rows]
145+
return [System.from_storage_dict(json.loads(r["data"]), node) for r in rows]
146146

147147
def delete_system(self, system_id: str) -> None:
148148
self._execute("DELETE FROM systems WHERE id = ?", (system_id,))
@@ -155,7 +155,7 @@ def delete_system(self, system_id: str) -> None:
155155
def save_datastream(self, datastream: Datastream, node: Node) -> None:
156156
ds_id = str(datastream.get_internal_id())
157157
system_id = datastream.get_parent_resource_id()
158-
data = json.dumps(datastream.serialize())
158+
data = json.dumps(datastream.to_storage_dict())
159159
self._execute(
160160
"INSERT OR REPLACE INTO datastreams (id, system_id, node_id, data) VALUES (?, ?, ?, ?)",
161161
(ds_id, system_id, node.get_id(), data),
@@ -168,13 +168,13 @@ def load_datastream(self, datastream_id: str, node: Node) -> Optional[Datastream
168168
).fetchone()
169169
if row is None:
170170
return None
171-
return Datastream.deserialize(json.loads(row["data"]), node)
171+
return Datastream.from_storage_dict(json.loads(row["data"]), node)
172172

173173
def load_datastreams_for_system(self, system_id: str, node: Node) -> list[Datastream]:
174174
rows = self._execute(
175175
"SELECT data FROM datastreams WHERE system_id = ?", (system_id,)
176176
).fetchall()
177-
return [Datastream.deserialize(json.loads(r["data"]), node) for r in rows]
177+
return [Datastream.from_storage_dict(json.loads(r["data"]), node) for r in rows]
178178

179179
def delete_datastream(self, datastream_id: str) -> None:
180180
self._execute("DELETE FROM datastreams WHERE id = ?", (datastream_id,))
@@ -187,7 +187,7 @@ def delete_datastream(self, datastream_id: str) -> None:
187187
def save_controlstream(self, controlstream: ControlStream, node: Node) -> None:
188188
cs_id = str(controlstream.get_internal_id())
189189
system_id = controlstream.get_parent_resource_id()
190-
data = json.dumps(controlstream.serialize())
190+
data = json.dumps(controlstream.to_storage_dict())
191191
self._execute(
192192
"INSERT OR REPLACE INTO controlstreams (id, system_id, node_id, data) VALUES (?, ?, ?, ?)",
193193
(cs_id, system_id, node.get_id(), data),
@@ -200,13 +200,13 @@ def load_controlstream(self, controlstream_id: str, node: Node) -> Optional[Cont
200200
).fetchone()
201201
if row is None:
202202
return None
203-
return ControlStream.deserialize(json.loads(row["data"]), node)
203+
return ControlStream.from_storage_dict(json.loads(row["data"]), node)
204204

205205
def load_controlstreams_for_system(self, system_id: str, node: Node) -> list[ControlStream]:
206206
rows = self._execute(
207207
"SELECT data FROM controlstreams WHERE system_id = ?", (system_id,)
208208
).fetchall()
209-
return [ControlStream.deserialize(json.loads(r["data"]), node) for r in rows]
209+
return [ControlStream.from_storage_dict(json.loads(r["data"]), node) for r in rows]
210210

211211
def delete_controlstream(self, controlstream_id: str) -> None:
212212
self._execute("DELETE FROM controlstreams WHERE id = ?", (controlstream_id,))
@@ -232,7 +232,7 @@ def load_all(
232232
) -> list[Node]:
233233
"""Reconstruct the full resource graph from the nodes table.
234234
235-
``Node.deserialize`` handles the embedded systems/datastreams/
235+
``Node.from_storage_dict`` handles the embedded systems/datastreams/
236236
controlstreams hierarchy, so only the *nodes* table is used here.
237237
The individual resource tables (systems, datastreams, controlstreams)
238238
exist for targeted single-resource lookups and are not consulted here

src/oshconnect/oshconnectapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def save_config(self):
9999

100100
data = {}
101101
for node in self._nodes:
102-
node_dict = node.serialize()
102+
node_dict = node.to_storage_dict()
103103
data.update({node.get_id(): node_dict})
104104

105105
# write to JSON file

0 commit comments

Comments
 (0)