Skip to content

Commit ba11e54

Browse files
committed
Expose bind argument for query method
1 parent c8a4c84 commit ba11e54

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

surrealdb/async_execution_mixins/query.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from __future__ import annotations
88

99
import json
10-
from typing import TYPE_CHECKING, List, Union
10+
from typing import TYPE_CHECKING, Any, List, Optional, Union
1111

1212
from surrealdb.errors import SurrealDbError
1313
from surrealdb.rust_surrealdb import (
@@ -22,16 +22,19 @@
2222
class AsyncQueryMixin:
2323
"""This class is responsible for the interface between python and the Rust SurrealDB library for creating a document."""
2424

25-
async def query(self: SurrealDB, query: str) -> List[dict]:
25+
async def query(
26+
self: SurrealDB, query: str, bind: Optional[dict[str, Any]] = None
27+
) -> List[dict]:
2628
"""
2729
queries the database.
2830
2931
:param query: the query to run on the database
32+
:param bind: Paramters to bind the query with.
3033
3134
:return: None
3235
"""
3336
try:
34-
return json.loads(await rust_query_future(self._connection, query))[0]
37+
return json.loads(await rust_query_future(self._connection, query, bind))[0]
3538
except Exception as e:
3639
raise SurrealDbError(e) from None
3740

surrealdb/execution_mixins/query.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import contextlib
1010
import json
11-
from typing import TYPE_CHECKING, List, Union
11+
from typing import TYPE_CHECKING, Any, Dict, List, Union, Optional
1212

1313
from surrealdb.asyncio_runtime import AsyncioRuntime
1414
from surrealdb.errors import SurrealDbError
@@ -43,17 +43,20 @@ def convert_nested_json_strings(data):
4343
item[key] = json.loads(value)
4444
return data
4545

46-
def query(self: SurrealDB, query: str) -> List[dict]:
46+
def query(
47+
self: SurrealDB, query: str, bind: Optional[Dict[str, Any]] = None
48+
) -> List[dict]:
4749
"""
4850
queries the database.
4951
5052
:param query: the query to run on the database
53+
:param bind: Paramters to bind the query with.
5154
5255
:return: None
5356
"""
5457

55-
async def _query(connection, query):
56-
return await rust_query_future(connection, query)
58+
async def _query(connection, query, bind):
59+
return await rust_query_future(connection, query, bind)
5760

5861
try:
5962
loop_manager = AsyncioRuntime()

0 commit comments

Comments
 (0)