6969"""
7070
7171
72- def fill_tables_with_data (pool , path ):
72+ def fill_tables_with_data (pool : ydb . QuerySessionPool , path : str ):
7373 print ("\n Filling tables with data..." )
7474
75- global FillDataQuery
75+ query = FillDataQuery . format ( path )
7676
77- def callee (session ):
78-
79- query = FillDataQuery .format (path )
80- with session .transaction (ydb .QuerySerializableReadWrite ()).execute (
81- query ,
82- {
83- "$seriesData" : (basic_example_data .get_series_data (), basic_example_data .get_series_data_type ()),
84- "$seasonsData" : (basic_example_data .get_seasons_data (), basic_example_data .get_seasons_data_type ()),
85- "$episodesData" : (basic_example_data .get_episodes_data (), basic_example_data .get_episodes_data_type ()),
86- },
87- commit_tx = True ,
88- ) as _ :
89- pass
90-
91- return pool .retry_operation_sync (callee )
77+ pool .execute_with_retries (
78+ query ,
79+ {
80+ "$seriesData" : (basic_example_data .get_series_data (), basic_example_data .get_series_data_type ()),
81+ "$seasonsData" : (basic_example_data .get_seasons_data (), basic_example_data .get_seasons_data_type ()),
82+ "$episodesData" : (basic_example_data .get_episodes_data (), basic_example_data .get_episodes_data_type ()),
83+ },
84+ )
9285
9386
94- def select_simple (pool , path ):
87+ def select_simple (pool : ydb . QuerySessionSync , path ):
9588 print ("\n Check series table..." )
9689 result_sets = pool .execute_with_retries (
9790 """
@@ -120,27 +113,22 @@ def select_simple(pool, path):
120113 return first_set
121114
122115
123- def upsert_simple (pool , path ):
116+ def upsert_simple (pool : ydb . QuerySessionPool , path ):
124117 print ("\n Performing UPSERT into episodes..." )
125118
126- def callee (session ):
127- with session .transaction ().execute (
128- """
129- PRAGMA TablePathPrefix("{}");
130- UPSERT INTO episodes (series_id, season_id, episode_id, title) VALUES (2, 6, 1, "TBD");
131- """ .format (
132- path
133- ),
134- commit_tx = True ,
135- ) as _ :
136- pass
137-
138- return pool .retry_operation_sync (callee )
119+ pool .execute_with_retries (
120+ """
121+ PRAGMA TablePathPrefix("{}");
122+ UPSERT INTO episodes (series_id, season_id, episode_id, title) VALUES (2, 6, 1, "TBD");
123+ """ .format (
124+ path
125+ )
126+ )
139127
140128
141129def select_with_parameters (pool , path , series_id , season_id , episode_id ):
142- def callee ( session ):
143- query = """
130+ result_sets = pool . execute_with_retries (
131+ """
144132 PRAGMA TablePathPrefix("{}");
145133 SELECT
146134 title,
@@ -149,25 +137,20 @@ def callee(session):
149137 WHERE series_id = $seriesId AND season_id = $seasonId AND episode_id = $episodeId;
150138 """ .format (
151139 path
152- )
153-
154- with session .transaction (ydb .QuerySerializableReadWrite ()).execute (
155- query ,
156- {
157- "$seriesId" : series_id , # could be defined implicit
158- "$seasonId" : (season_id , ydb .PrimitiveType .Int64 ), # could be defined via tuple
159- "$episodeId" : ydb .TypedValue (episode_id , ydb .PrimitiveType .Int64 ), # could be defined via special class
160- },
161- commit_tx = True ,
162- ) as result_sets :
163- print ("\n > select_prepared_transaction:" )
164- first_set = next (result_sets )
165- for row in first_set .rows :
166- print ("episode title:" , row .title , ", air date:" , row .air_date )
140+ ),
141+ {
142+ "$seriesId" : series_id , # could be defined implicit
143+ "$seasonId" : (season_id , ydb .PrimitiveType .Int64 ), # could be defined via tuple
144+ "$episodeId" : ydb .TypedValue (episode_id , ydb .PrimitiveType .Int64 ), # could be defined via special class
145+ }
146+ )
167147
168- return first_set
148+ print ("\n > select_with_parameters:" )
149+ first_set = result_sets [0 ]
150+ for row in first_set .rows :
151+ print ("episode title:" , row .title , ", air date:" , row .air_date )
169152
170- return pool . retry_operation_sync ( callee )
153+ return first_set
171154
172155
173156# Show usage of explicit Begin/Commit transaction control calls.
0 commit comments