Skip to content

Commit 8ba7570

Browse files
Allow concurrent query for async ws connections (#167)
Co-authored-by: Maxwell Flitton <[email protected]>
1 parent 3499108 commit 8ba7570

24 files changed

+104
-169
lines changed

src/surrealdb/connections/async_template.py

+37-37
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class AsyncTemplate:
99

10-
async def connect(self, url: str) -> Coroutine[Any, Any, None]:
10+
async def connect(self, url: str) -> None:
1111
"""Connects to a local or remote database endpoint.
1212
1313
Args:
@@ -18,17 +18,17 @@ async def connect(self, url: str) -> Coroutine[Any, Any, None]:
1818
# Connect to a remote endpoint
1919
await db.connect('https://cloud.surrealdb.com/rpc');
2020
"""
21-
raise NotImplementedError(f"query not implemented for: {self}")
21+
raise NotImplementedError(f"connect not implemented for: {self}")
2222

23-
async def close(self) -> Coroutine[Any, Any, None]:
23+
async def close(self) -> None:
2424
"""Closes the persistent connection to the database.
2525
2626
Example:
2727
await db.close()
2828
"""
29-
raise NotImplementedError(f"query not implemented for: {self}")
29+
raise NotImplementedError(f"close not implemented for: {self}")
3030

31-
async def use(self, namespace: str, database: str) -> Coroutine[Any, Any, None]:
31+
async def use(self, namespace: str, database: str) -> None:
3232
"""Switch to a specific namespace and database.
3333
3434
Args:
@@ -38,9 +38,9 @@ async def use(self, namespace: str, database: str) -> Coroutine[Any, Any, None]:
3838
Example:
3939
await db.use('test', 'test')
4040
"""
41-
raise NotImplementedError(f"query not implemented for: {self}")
41+
raise NotImplementedError(f"use not implemented for: {self}")
4242

43-
async def authenticate(self, token: str) -> Coroutine[Any, Any, None]:
43+
async def authenticate(self, token: str) -> None:
4444
"""Authenticate the current connection with a JWT token.
4545
4646
Args:
@@ -51,15 +51,15 @@ async def authenticate(self, token: str) -> Coroutine[Any, Any, None]:
5151
"""
5252
raise NotImplementedError(f"authenticate not implemented for: {self}")
5353

54-
async def invalidate(self) -> Coroutine[Any, Any, None]:
54+
async def invalidate(self) -> None:
5555
"""Invalidate the authentication for the current connection.
5656
5757
Example:
5858
await db.invalidate()
5959
"""
6060
raise NotImplementedError(f"invalidate not implemented for: {self}")
6161

62-
async def signup(self, vars: Dict) -> Coroutine[Any, Any, str]:
62+
async def signup(self, vars: Dict) -> str:
6363
"""Sign this connection up to a specific authentication scope.
6464
[See the docs](https://surrealdb.com/docs/sdk/python/methods/signup)
6565
@@ -81,7 +81,7 @@ async def signup(self, vars: Dict) -> Coroutine[Any, Any, str]:
8181
"""
8282
raise NotImplementedError(f"signup not implemented for: {self}")
8383

84-
async def signin(self, vars: Dict) -> Coroutine[Any, Any, str]:
84+
async def signin(self, vars: Dict) -> str:
8585
"""Sign this connection in to a specific authentication scope.
8686
[See the docs](https://surrealdb.com/docs/sdk/python/methods/signin)
8787
@@ -94,9 +94,9 @@ async def signin(self, vars: Dict) -> Coroutine[Any, Any, str]:
9494
password: 'surrealdb',
9595
})
9696
"""
97-
raise NotImplementedError(f"query not implemented for: {self}")
97+
raise NotImplementedError(f"signin not implemented for: {self}")
9898

99-
async def let(self, key: str, value: Any) -> Coroutine[Any, Any, None]:
99+
async def let(self, key: str, value: Any) -> None:
100100
"""Assign a value as a variable for this connection.
101101
102102
Args:
@@ -115,7 +115,7 @@ async def let(self, key: str, value: Any) -> Coroutine[Any, Any, None]:
115115
"""
116116
raise NotImplementedError(f"let not implemented for: {self}")
117117

118-
async def unset(self, key: str) -> Coroutine[Any, Any, None]:
118+
async def unset(self, key: str) -> None:
119119
"""Removes a variable for this connection.
120120
121121
Args:
@@ -124,11 +124,11 @@ async def unset(self, key: str) -> Coroutine[Any, Any, None]:
124124
Example:
125125
await db.unset('name')
126126
"""
127-
raise NotImplementedError(f"let not implemented for: {self}")
127+
raise NotImplementedError(f"unset not implemented for: {self}")
128128

129129
async def query(
130130
self, query: str, vars: Optional[Dict] = None
131-
) -> Coroutine[Any, Any, Union[List[dict], dict]]:
131+
) -> Union[List[dict], dict]:
132132
"""Run a unset of SurrealQL statements against the database.
133133
134134
Args:
@@ -145,7 +145,7 @@ async def query(
145145

146146
async def select(
147147
self, thing: Union[str, RecordID, Table]
148-
) -> Coroutine[Any, Any, Union[List[dict], dict]]:
148+
) -> Union[List[dict], dict]:
149149
"""Select all records in a table (or other entity),
150150
or a specific record, in the database.
151151
@@ -158,13 +158,13 @@ async def select(
158158
Example:
159159
db.select('person')
160160
"""
161-
raise NotImplementedError(f"query not implemented for: {self}")
161+
raise NotImplementedError(f"select not implemented for: {self}")
162162

163163
async def create(
164164
self,
165165
thing: Union[str, RecordID, Table],
166166
data: Optional[Union[List[dict], dict]] = None,
167-
) -> Coroutine[Any, Any, Union[List[dict], dict]]:
167+
) -> Union[List[dict], dict]:
168168
"""Create a record in the database.
169169
170170
This function will run the following query in the database:
@@ -181,7 +181,7 @@ async def create(
181181

182182
async def update(
183183
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
184-
) -> Coroutine[Any, Any, Union[List[dict], dict]]:
184+
) -> Union[List[dict], dict]:
185185
"""Update all records in a table, or a specific record, in the database.
186186
187187
This function replaces the current document / record data with the
@@ -207,11 +207,11 @@ async def update(
207207
},
208208
})
209209
"""
210-
raise NotImplementedError(f"query not implemented for: {self}")
210+
raise NotImplementedError(f"update not implemented for: {self}")
211211

212212
async def upsert(
213213
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
214-
) -> Coroutine[Any, Any, Union[List[dict], dict]]:
214+
) -> Union[List[dict], dict]:
215215
"""Insert records into the database, or to update them if they exist.
216216
217217
@@ -239,7 +239,7 @@ async def upsert(
239239

240240
async def merge(
241241
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
242-
) -> Coroutine[Any, Any, Union[List[dict], dict]]:
242+
) -> Union[List[dict], dict]:
243243
"""Modify by deep merging all records in a table, or a specific record, in the database.
244244
245245
This function merges the current document / record data with the
@@ -267,11 +267,11 @@ async def merge(
267267
})
268268
269269
"""
270-
raise NotImplementedError(f"query not implemented for: {self}")
270+
raise NotImplementedError(f"merge not implemented for: {self}")
271271

272272
async def patch(
273273
self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None
274-
) -> Coroutine[Any, Any, Union[List[dict], dict]]:
274+
) -> Union[List[dict], dict]:
275275
"""Apply JSON Patch changes to all records, or a specific record, in the database.
276276
277277
This function patches the current document / record data with
@@ -296,11 +296,11 @@ async def patch(
296296
{ 'op': "remove", "path": "/temp" },
297297
])
298298
"""
299-
raise NotImplementedError(f"query not implemented for: {self}")
299+
raise NotImplementedError(f"patch not implemented for: {self}")
300300

301301
async def delete(
302302
self, thing: Union[str, RecordID, Table]
303-
) -> Coroutine[Any, Any, Union[List[dict], dict]]:
303+
) -> Union[List[dict], dict]:
304304
"""Delete all records in a table, or a specific record, from the database.
305305
306306
This function will run the following query in the database:
@@ -324,11 +324,11 @@ async def info(self) -> Coroutine[Any, Any, dict]:
324324
Example:
325325
await db.info()
326326
"""
327-
raise NotImplementedError(f"query not implemented for: {self}")
327+
raise NotImplementedError(f"info not implemented for: {self}")
328328

329329
async def insert(
330330
self, table: Union[str, Table], data: Union[List[dict], dict]
331-
) -> Coroutine[Any, Any, Union[List[dict], dict]]:
331+
) -> Union[List[dict], dict]:
332332
"""
333333
Inserts one or multiple records in the database.
334334
@@ -343,11 +343,11 @@ async def insert(
343343
await db.insert('person', [{ name: 'Tobie'}, { name: 'Jaime'}])
344344
345345
"""
346-
raise NotImplementedError(f"query not implemented for: {self}")
346+
raise NotImplementedError(f"insert not implemented for: {self}")
347347

348348
async def insert_relation(
349349
self, table: Union[str, Table], data: Union[List[dict], dict]
350-
) -> Coroutine[Any, Any, Union[List[dict], dict]]:
350+
) -> Union[List[dict], dict]:
351351
"""
352352
Inserts one or multiple relations in the database.
353353
@@ -362,11 +362,11 @@ async def insert_relation(
362362
await db.insert_relation('likes', { in: person:1, id: 'object', out: person:2})
363363
364364
"""
365-
raise NotImplementedError(f"query not implemented for: {self}")
365+
raise NotImplementedError(f"insert_relation not implemented for: {self}")
366366

367367
async def live(
368368
self, table: Union[str, Table], diff: bool = False
369-
) -> Coroutine[Any, Any, UUID]:
369+
) -> UUID:
370370
"""Initiates a live query for a specified table name.
371371
372372
Args:
@@ -381,11 +381,11 @@ async def live(
381381
Example:
382382
await db.live('person')
383383
"""
384-
raise NotImplementedError(f"query not implemented for: {self}")
384+
raise NotImplementedError(f"live not implemented for: {self}")
385385

386386
async def subscribe_live(
387387
self, query_uuid: Union[str, UUID]
388-
) -> Coroutine[Any, Any, Queue]:
388+
) -> Queue:
389389
"""Returns a queue that receives notification messages from a running live query.
390390
391391
Args:
@@ -397,9 +397,9 @@ async def subscribe_live(
397397
Example:
398398
await db.subscribe_live(UUID)
399399
"""
400-
raise NotImplementedError(f"query not implemented for: {self}")
400+
raise NotImplementedError(f"subscribe_live not implemented for: {self}")
401401

402-
async def kill(self, query_uuid: Union[str, UUID]) -> Coroutine[Any, Any, None]:
402+
async def kill(self, query_uuid: Union[str, UUID]) -> None:
403403
"""Kills a running live query by it's UUID.
404404
405405
Args:
@@ -409,4 +409,4 @@ async def kill(self, query_uuid: Union[str, UUID]) -> Coroutine[Any, Any, None]:
409409
await db.kill(UUID)
410410
411411
"""
412-
raise NotImplementedError(f"query not implemented for: {self}")
412+
raise NotImplementedError(f"kill not implemented for: {self}")

0 commit comments

Comments
 (0)