Skip to content

Commit cab73b1

Browse files
committed
ddl and dml queries
1 parent 1ed9b8c commit cab73b1

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

ydb_dbapi/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async def describe(self, table_path: str) -> ydb.TableSchemeEntry:
142142
return self.driver.table_client.describe_table(abs_table_path)
143143

144144
@handle_ydb_errors
145-
async def check_exists(self, table_path: str) -> ydb.SchemeEntry:
145+
async def check_exists(self, table_path: str) -> bool:
146146
abs_table_path = posixpath.join(
147147
self.database, self.table_path_prefix, table_path
148148
)
@@ -154,7 +154,7 @@ async def get_table_names(self) -> List[str]:
154154
names = await self._get_table_names(abs_dir_path)
155155
return [posixpath.relpath(path, abs_dir_path) for path in names]
156156

157-
async def _check_path_exists(self, table_path: str) -> ydb.SchemeEntry:
157+
async def _check_path_exists(self, table_path: str) -> bool:
158158
try:
159159
await retry_operation_async(
160160
self.driver.scheme_client.describe_path, table_path

ydb_dbapi/cursors.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dataclasses
2+
import typing
23
from typing import (
34
Any,
45
Dict,
@@ -10,6 +11,9 @@
1011

1112
import ydb
1213

14+
if typing.TYPE_CHECKING:
15+
from ydb.aio.query.base import AsyncResponseContextIterator
16+
1317

1418
ParametersType = Dict[
1519
str,
@@ -32,9 +36,10 @@ def __init__(
3236
self,
3337
session_pool: ydb.aio.QuerySessionPool,
3438
session: ydb.aio.QuerySession,
35-
tx_mode: ydb.BaseQueryTxMode,
36-
tx_context: Optional[ydb.QueryTxContext] = None,
39+
tx_mode: ydb.aio.QueryTxContext,
40+
tx_context: ydb.aio.QueryTxContext,
3741
table_path_prefix: str = "",
42+
autocommit: bool = True,
3843
):
3944
self.arraysize = 1
4045
self._description = None
@@ -44,18 +49,37 @@ def __init__(
4449
self._tx_mode = tx_mode
4550
self._tx_context = tx_context
4651
self._table_path_prefix = table_path_prefix
52+
self._autocommit = autocommit
4753

4854
async def _execute_ddl_query(
49-
self, query: YdbQuery, parameters: Optional[ParametersType] = None
55+
self, query: str, parameters: Optional[ParametersType] = None
5056
) -> List[ydb.convert.ResultSet]:
5157
return await self._pool.execute_with_retries(
5258
query=query, parameters=parameters
5359
)
5460

61+
async def _execute_dml_query(
62+
self, query: str, parameters: Optional[ParametersType] = None
63+
) -> AsyncResponseContextIterator:
64+
return await self._tx_context.execute(
65+
query=query,
66+
parameters=parameters,
67+
commit_tx=self._autocommit,
68+
)
69+
5570
async def execute(
5671
self, operation: YdbQuery, parameters: Optional[ParametersType] = None
5772
):
58-
pass
73+
if operation.is_ddl:
74+
result_sets = await self._execute_ddl_query(
75+
query=operation.yql_text, parameters=parameters
76+
)
77+
else:
78+
result_sets_stream = await self._execute_dml_query(
79+
query=operation.yql_text, parameters=parameters
80+
)
81+
82+
return result_sets or result_sets_stream
5983

6084
async def executemany(self):
6185
pass

0 commit comments

Comments
 (0)