File tree Expand file tree Collapse file tree 1 file changed +43
-4
lines changed
Expand file tree Collapse file tree 1 file changed +43
-4
lines changed Original file line number Diff line number Diff line change 1+ from typing import (
2+ Any ,
3+ Optional ,
4+ )
5+
6+ import ydb
7+
8+
19class Connection :
2- def __init__ (self ):
3- pass
10+ def __init__ (
11+ self ,
12+ host : str = "" ,
13+ port : str = "" ,
14+ database : str = "" ,
15+ ** conn_kwargs : Any ,
16+ ):
17+ self .endpoint = f"grpc://{ host } :{ port } "
18+ self .database = database
19+ self .conn_kwargs = conn_kwargs
20+ self .credentials = self .conn_kwargs .pop ("credentials" , None )
21+ self .table_path_prefix = self .conn_kwargs .pop (
22+ "ydb_table_path_prefix" , ""
23+ )
24+
25+ self .session_pool : ydb .aio .QuerySessionPool = None
26+ self .session : ydb .aio .QuerySession = None
27+ self .tx_context : Optional [ydb .QueryTxContext ] = None
28+ self .tx_mode : ydb .BaseQueryTxMode = ydb .QuerySerializableReadWrite ()
429
530 def cursor (self ):
631 pass
732
33+ async def begin (self ):
34+ self .tx_context = None
35+ self .session = await self .session_pool .acquire ()
36+ self .tx_context = self .session .transaction (self .tx_mode )
37+ await self .tx_context .begin ()
38+
839 async def commit (self ):
9- pass
40+ if self .tx_context and self .tx_context .tx_id :
41+ await self .tx_context .commit ()
42+ await self .session_pool .release (self .session )
43+ self .session = None
44+ self .tx_context = None
1045
1146 async def rollback (self ):
12- pass
47+ if self .tx_context and self .tx_context .tx_id :
48+ await self .tx_context .rollback ()
49+ await self .session_pool .release (self .session )
50+ self .session = None
51+ self .tx_context = None
1352
1453 async def close (self ):
1554 pass
You can’t perform that action at this time.
0 commit comments