Skip to content

Commit 0f30f93

Browse files
formatting code
1 parent 58604a1 commit 0f30f93

File tree

6 files changed

+39
-100
lines changed

6 files changed

+39
-100
lines changed

src/surrealdb/connections/async_http.py

+6-18
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ async def create(
188188
if ":" in thing:
189189
buffer = thing.split(":")
190190
thing = RecordID(table_name=buffer[0], identifier=buffer[1])
191-
message = RequestMessage(
192-
RequestMethod.CREATE, collection=thing, data=data
193-
)
191+
message = RequestMessage(RequestMethod.CREATE, collection=thing, data=data)
194192
self.id = message.id
195193
response = await self._send(message, "create")
196194
self.check_response_for_result(response, "create")
@@ -208,9 +206,7 @@ async def delete(
208206
async def insert(
209207
self, table: Union[str, Table], data: Union[List[dict], dict]
210208
) -> Union[List[dict], dict]:
211-
message = RequestMessage(
212-
RequestMethod.INSERT, collection=table, params=data
213-
)
209+
message = RequestMessage(RequestMethod.INSERT, collection=table, params=data)
214210
self.id = message.id
215211
response = await self._send(message, "insert")
216212
self.check_response_for_result(response, "insert")
@@ -236,9 +232,7 @@ async def unset(self, key: str) -> None:
236232
async def merge(
237233
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
238234
) -> Union[List[dict], dict]:
239-
message = RequestMessage(
240-
RequestMethod.MERGE, record_id=thing, data=data
241-
)
235+
message = RequestMessage(RequestMethod.MERGE, record_id=thing, data=data)
242236
self.id = message.id
243237
response = await self._send(message, "merge")
244238
self.check_response_for_result(response, "merge")
@@ -247,9 +241,7 @@ async def merge(
247241
async def patch(
248242
self, thing: Union[str, RecordID, Table], data: Optional[List[dict]] = None
249243
) -> Union[List[dict], dict]:
250-
message = RequestMessage(
251-
RequestMethod.PATCH, collection=thing, params=data
252-
)
244+
message = RequestMessage(RequestMethod.PATCH, collection=thing, params=data)
253245
self.id = message.id
254246
response = await self._send(message, "patch")
255247
self.check_response_for_result(response, "patch")
@@ -265,9 +257,7 @@ async def select(self, thing: str) -> Union[List[dict], dict]:
265257
async def update(
266258
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
267259
) -> Union[List[dict], dict]:
268-
message = RequestMessage(
269-
RequestMethod.UPDATE, record_id=thing, data=data
270-
)
260+
message = RequestMessage(RequestMethod.UPDATE, record_id=thing, data=data)
271261
self.id = message.id
272262
response = await self._send(message, "update")
273263
self.check_response_for_result(response, "update")
@@ -283,9 +273,7 @@ async def version(self) -> str:
283273
async def upsert(
284274
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
285275
) -> Union[List[dict], dict]:
286-
message = RequestMessage(
287-
RequestMethod.UPSERT, record_id=thing, data=data
288-
)
276+
message = RequestMessage(RequestMethod.UPSERT, record_id=thing, data=data)
289277
self.id = message.id
290278
response = await self._send(message, "upsert")
291279
self.check_response_for_result(response, "upsert")

src/surrealdb/connections/async_template.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,7 @@ async def insert_relation(
364364
"""
365365
raise NotImplementedError(f"insert_relation not implemented for: {self}")
366366

367-
async def live(
368-
self, table: Union[str, Table], diff: bool = False
369-
) -> UUID:
367+
async def live(self, table: Union[str, Table], diff: bool = False) -> UUID:
370368
"""Initiates a live query for a specified table name.
371369
372370
Args:
@@ -383,9 +381,7 @@ async def live(
383381
"""
384382
raise NotImplementedError(f"live not implemented for: {self}")
385383

386-
async def subscribe_live(
387-
self, query_uuid: Union[str, UUID]
388-
) -> Queue:
384+
async def subscribe_live(self, query_uuid: Union[str, UUID]) -> Queue:
389385
"""Returns a queue that receives notification messages from a running live query.
390386
391387
Args:

src/surrealdb/connections/async_ws.py

+19-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
A basic async connection to a SurrealDB instance.
33
"""
4+
45
import asyncio
56
from asyncio import Queue, Task, Future, AbstractEventLoop
67
from typing import Optional, Any, Dict, Union, List
@@ -46,22 +47,22 @@ def __init__(
4647
self.port: Optional[int] = self.url.port
4748
self.token: Optional[str] = None
4849
self.socket = None
49-
self.loop: AbstractEventLoop|None = None
50-
self.qry:dict[str, Future] = {}
51-
self.recv_task:Task[None]|None = None
52-
self.live_queues:dict[str, list] = {}
50+
self.loop: AbstractEventLoop | None = None
51+
self.qry: dict[str, Future] = {}
52+
self.recv_task: Task[None] | None = None
53+
self.live_queues: dict[str, list] = {}
5354

5455
async def _recv_task(self):
5556
assert self.socket
5657
async for data in self.socket:
5758
response = decode(data)
58-
if (response_id := response.get("id")):
59+
if response_id := response.get("id"):
5960
if fut := self.qry.get(response_id):
6061
fut.set_result(response)
6162
else:
62-
live_id = str(response['result']['id'])
63+
live_id = str(response["result"]["id"])
6364
for queue in self.live_queues.get(live_id, []):
64-
queue.put_nowait(response['result'])
65+
queue.put_nowait(response["result"])
6566

6667
async def _send(
6768
self, message: RequestMessage, process: str, bypass: bool = False
@@ -206,39 +207,31 @@ async def create(
206207
if ":" in thing:
207208
buffer = thing.split(":")
208209
thing = RecordID(table_name=buffer[0], identifier=buffer[1])
209-
message = RequestMessage(
210-
RequestMethod.CREATE, collection=thing, data=data
211-
)
210+
message = RequestMessage(RequestMethod.CREATE, collection=thing, data=data)
212211
response = await self._send(message, "create")
213212
self.check_response_for_result(response, "create")
214213
return response["result"]
215214

216215
async def update(
217216
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
218217
) -> Union[List[dict], dict]:
219-
message = RequestMessage(
220-
RequestMethod.UPDATE, record_id=thing, data=data
221-
)
218+
message = RequestMessage(RequestMethod.UPDATE, record_id=thing, data=data)
222219
response = await self._send(message, "update")
223220
self.check_response_for_result(response, "update")
224221
return response["result"]
225222

226223
async def merge(
227224
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
228225
) -> Union[List[dict], dict]:
229-
message = RequestMessage(
230-
RequestMethod.MERGE, record_id=thing, data=data
231-
)
226+
message = RequestMessage(RequestMethod.MERGE, record_id=thing, data=data)
232227
response = await self._send(message, "merge")
233228
self.check_response_for_result(response, "merge")
234229
return response["result"]
235230

236231
async def patch(
237232
self, thing: Union[str, RecordID, Table], data: Optional[List[dict]] = None
238233
) -> Union[List[dict], dict]:
239-
message = RequestMessage(
240-
RequestMethod.PATCH, collection=thing, params=data
241-
)
234+
message = RequestMessage(RequestMethod.PATCH, collection=thing, params=data)
242235
response = await self._send(message, "patch")
243236
self.check_response_for_result(response, "patch")
244237
return response["result"]
@@ -254,9 +247,7 @@ async def delete(
254247
async def insert(
255248
self, table: Union[str, Table], data: Union[List[dict], dict]
256249
) -> Union[List[dict], dict]:
257-
message = RequestMessage(
258-
RequestMethod.INSERT, collection=table, params=data
259-
)
250+
message = RequestMessage(RequestMethod.INSERT, collection=table, params=data)
260251
response = await self._send(message, "insert")
261252
self.check_response_for_result(response, "insert")
262253
return response["result"]
@@ -283,16 +274,16 @@ async def live(self, table: Union[str, Table], diff: bool = False) -> UUID:
283274
self.live_queues[str(uuid)] = []
284275
return uuid
285276

286-
def subscribe_live(
287-
self, query_uuid: Union[str, UUID]
288-
) -> Queue:
277+
def subscribe_live(self, query_uuid: Union[str, UUID]) -> Queue:
289278
result_queue = Queue()
290279
suid = str(query_uuid)
291280
self.live_queues[suid].append(result_queue)
281+
292282
async def _iter():
293283
while True:
294284
ret = await result_queue.get()
295-
yield ret['result']
285+
yield ret["result"]
286+
296287
return _iter()
297288

298289
async def kill(self, query_uuid: Union[str, UUID]) -> None:
@@ -303,9 +294,7 @@ async def kill(self, query_uuid: Union[str, UUID]) -> None:
303294
async def upsert(
304295
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
305296
) -> Union[List[dict], dict]:
306-
message = RequestMessage(
307-
RequestMethod.UPSERT, record_id=thing, data=data
308-
)
297+
message = RequestMessage(RequestMethod.UPSERT, record_id=thing, data=data)
309298
response = await self._send(message, "upsert")
310299
self.check_response_for_result(response, "upsert")
311300
return response["result"]
@@ -321,7 +310,6 @@ async def close(self):
321310
if self.socket is not None:
322311
await self.socket.close()
323312

324-
325313
async def __aenter__(self) -> "AsyncWsSurrealConnection":
326314
"""
327315
Asynchronous context manager entry.
@@ -335,4 +323,4 @@ async def __aexit__(self, exc_type, exc_value, traceback) -> None:
335323
Asynchronous context manager exit.
336324
Closes the websocket connection upon exiting the context.
337325
"""
338-
await self.close()
326+
await self.close()

src/surrealdb/connections/blocking_http.py

+6-18
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ def create(
147147
if ":" in thing:
148148
buffer = thing.split(":")
149149
thing = RecordID(table_name=buffer[0], identifier=buffer[1])
150-
message = RequestMessage(
151-
RequestMethod.CREATE, collection=thing, data=data
152-
)
150+
message = RequestMessage(RequestMethod.CREATE, collection=thing, data=data)
153151
self.id = message.id
154152
response = self._send(message, "create")
155153
self.check_response_for_result(response, "create")
@@ -165,9 +163,7 @@ def delete(self, thing: Union[str, RecordID, Table]) -> Union[List[dict], dict]:
165163
def insert(
166164
self, table: Union[str, Table], data: Union[List[dict], dict]
167165
) -> Union[List[dict], dict]:
168-
message = RequestMessage(
169-
RequestMethod.INSERT, collection=table, params=data
170-
)
166+
message = RequestMessage(RequestMethod.INSERT, collection=table, params=data)
171167
self.id = message.id
172168
response = self._send(message, "insert")
173169
self.check_response_for_result(response, "insert")
@@ -193,9 +189,7 @@ def unset(self, key: str) -> None:
193189
def merge(
194190
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
195191
) -> Union[List[dict], dict]:
196-
message = RequestMessage(
197-
RequestMethod.MERGE, record_id=thing, data=data
198-
)
192+
message = RequestMessage(RequestMethod.MERGE, record_id=thing, data=data)
199193
self.id = message.id
200194
response = self._send(message, "merge")
201195
self.check_response_for_result(response, "merge")
@@ -204,9 +198,7 @@ def merge(
204198
def patch(
205199
self, thing: Union[str, RecordID, Table], data: Optional[Dict[Any, Any]] = None
206200
) -> Union[List[dict], dict]:
207-
message = RequestMessage(
208-
RequestMethod.PATCH, collection=thing, params=data
209-
)
201+
message = RequestMessage(RequestMethod.PATCH, collection=thing, params=data)
210202
self.id = message.id
211203
response = self._send(message, "patch")
212204
self.check_response_for_result(response, "patch")
@@ -222,9 +214,7 @@ def select(self, thing: Union[str, RecordID, Table]) -> Union[List[dict], dict]:
222214
def update(
223215
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
224216
) -> Union[List[dict], dict]:
225-
message = RequestMessage(
226-
RequestMethod.UPDATE, record_id=thing, data=data
227-
)
217+
message = RequestMessage(RequestMethod.UPDATE, record_id=thing, data=data)
228218
self.id = message.id
229219
response = self._send(message, "update")
230220
self.check_response_for_result(response, "update")
@@ -240,9 +230,7 @@ def version(self) -> str:
240230
def upsert(
241231
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
242232
) -> Union[List[dict], dict]:
243-
message = RequestMessage(
244-
RequestMethod.UPSERT, record_id=thing, data=data
245-
)
233+
message = RequestMessage(RequestMethod.UPSERT, record_id=thing, data=data)
246234
self.id = message.id
247235
response = self._send(message, "upsert")
248236
self.check_response_for_result(response, "upsert")

src/surrealdb/connections/blocking_ws.py

+6-18
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,7 @@ def create(
169169
if ":" in thing:
170170
buffer = thing.split(":")
171171
thing = RecordID(table_name=buffer[0], identifier=buffer[1])
172-
message = RequestMessage(
173-
RequestMethod.CREATE, collection=thing, data=data
174-
)
172+
message = RequestMessage(RequestMethod.CREATE, collection=thing, data=data)
175173
self.id = message.id
176174
response = self._send(message, "create")
177175
self.check_response_for_result(response, "create")
@@ -202,9 +200,7 @@ def delete(self, thing: Union[str, RecordID, Table]) -> Union[List[dict], dict]:
202200
def insert(
203201
self, table: Union[str, Table], data: Union[List[dict], dict]
204202
) -> Union[List[dict], dict]:
205-
message = RequestMessage(
206-
RequestMethod.INSERT, collection=table, params=data
207-
)
203+
message = RequestMessage(RequestMethod.INSERT, collection=table, params=data)
208204
self.id = message.id
209205
response = self._send(message, "insert")
210206
self.check_response_for_result(response, "insert")
@@ -224,9 +220,7 @@ def insert_relation(
224220
def merge(
225221
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
226222
) -> Union[List[dict], dict]:
227-
message = RequestMessage(
228-
RequestMethod.MERGE, record_id=thing, data=data
229-
)
223+
message = RequestMessage(RequestMethod.MERGE, record_id=thing, data=data)
230224
self.id = message.id
231225
response = self._send(message, "merge")
232226
self.check_response_for_result(response, "merge")
@@ -235,9 +229,7 @@ def merge(
235229
def patch(
236230
self, thing: Union[str, RecordID, Table], data: Optional[List[dict]] = None
237231
) -> Union[List[dict], dict]:
238-
message = RequestMessage(
239-
RequestMethod.PATCH, collection=thing, params=data
240-
)
232+
message = RequestMessage(RequestMethod.PATCH, collection=thing, params=data)
241233
self.id = message.id
242234
response = self._send(message, "patch")
243235
self.check_response_for_result(response, "patch")
@@ -275,9 +267,7 @@ def subscribe_live(
275267
def update(
276268
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
277269
) -> Union[List[dict], dict]:
278-
message = RequestMessage(
279-
RequestMethod.UPDATE, record_id=thing, data=data
280-
)
270+
message = RequestMessage(RequestMethod.UPDATE, record_id=thing, data=data)
281271
self.id = message.id
282272
response = self._send(message, "update")
283273
self.check_response_for_result(response, "update")
@@ -286,9 +276,7 @@ def update(
286276
def upsert(
287277
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
288278
) -> Union[List[dict], dict]:
289-
message = RequestMessage(
290-
RequestMethod.UPSERT, record_id=thing, data=data
291-
)
279+
message = RequestMessage(RequestMethod.UPSERT, record_id=thing, data=data)
292280
self.id = message.id
293281
response = self._send(message, "upsert")
294282
self.check_response_for_result(response, "upsert")

src/surrealdb/connections/socket_state.py

-9
This file was deleted.

0 commit comments

Comments
 (0)