Skip to content

Commit 694bce2

Browse files
committed
add table prefix pragma to queries
1 parent 68fc6cf commit 694bce2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

ydb_dbapi/cursors.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def __init__(self) -> None:
3939
self._description: list[tuple] | None = None
4040
self._state: CursorStatus = CursorStatus.ready
4141

42+
self._table_path_prefix: str = ""
43+
4244
@property
4345
def description(self) -> list[tuple] | None:
4446
return self._description
@@ -134,6 +136,12 @@ def _fetchall_from_buffer(self) -> list:
134136
self._raise_if_closed()
135137
return list(self._rows or iter([]))
136138

139+
def _append_table_path_prefix(self, query: str) -> str:
140+
if self._table_path_prefix:
141+
prgm = f'PRAGMA TablePathPrefix = "{self._table_path_prefix}";\n'
142+
return prgm + query
143+
return query
144+
137145

138146
class Cursor(BufferedCursor):
139147
def __init__(
@@ -225,6 +233,9 @@ def execute(
225233
) -> None:
226234
self._raise_if_closed()
227235
self._raise_if_running()
236+
237+
query = self._append_table_path_prefix(query)
238+
228239
if self._tx_context is not None:
229240
self._stream = self._execute_transactional_query(
230241
tx_context=self._tx_context, query=query, parameters=parameters
@@ -376,6 +387,9 @@ async def execute(
376387
) -> None:
377388
self._raise_if_closed()
378389
self._raise_if_running()
390+
391+
query = self._append_table_path_prefix(query)
392+
379393
if self._tx_context is not None:
380394
self._stream = await self._execute_transactional_query(
381395
tx_context=self._tx_context, query=query, parameters=parameters

0 commit comments

Comments
 (0)