69
69
"""
70
70
71
71
72
- def fill_tables_with_data (pool , path ):
72
+ def fill_tables_with_data (pool : ydb . QuerySessionPool , path : str ):
73
73
print ("\n Filling tables with data..." )
74
74
75
- global FillDataQuery
75
+ query = FillDataQuery . format ( path )
76
76
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
+ )
92
85
93
86
94
- def select_simple (pool , path ):
87
+ def select_simple (pool : ydb . QuerySessionSync , path ):
95
88
print ("\n Check series table..." )
96
89
result_sets = pool .execute_with_retries (
97
90
"""
@@ -120,27 +113,22 @@ def select_simple(pool, path):
120
113
return first_set
121
114
122
115
123
- def upsert_simple (pool , path ):
116
+ def upsert_simple (pool : ydb . QuerySessionPool , path ):
124
117
print ("\n Performing UPSERT into episodes..." )
125
118
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
+ )
139
127
140
128
141
129
def 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
+ """
144
132
PRAGMA TablePathPrefix("{}");
145
133
SELECT
146
134
title,
@@ -149,25 +137,20 @@ def callee(session):
149
137
WHERE series_id = $seriesId AND season_id = $seasonId AND episode_id = $episodeId;
150
138
""" .format (
151
139
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
+ )
167
147
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 )
169
152
170
- return pool . retry_operation_sync ( callee )
153
+ return first_set
171
154
172
155
173
156
# Show usage of explicit Begin/Commit transaction control calls.
0 commit comments