@@ -31,112 +31,79 @@ public static async Task Run(
31
31
App code snippet for creating a session:
32
32
33
33
``` c#
34
- using var tableClient = new TableClient (driver , new TableClientConfig () );
34
+ using var queryClient = new QueryService (driver );
35
35
```
36
36
37
37
{% include [ steps/02_create_table.md] ( steps/02_create_table.md ) %}
38
38
39
- To create tables, use the ` session.ExecuteSchemeQuery ` method with a DDL (Data Definition Language) YQL query.
39
+ To create tables, use the ` queryClient.Exec ` method with a DDL (Data Definition Language) YQL query.
40
40
41
41
``` c#
42
- var response = await tableClient .SessionExec (async session =>
43
- {
44
- return await session .ExecuteSchemeQuery (@"
45
- CREATE TABLE series (
46
- series_id Uint64 NOT NULL,
47
- title Utf8,
48
- series_info Utf8,
49
- release_date Date,
50
- PRIMARY KEY (series_id)
51
- );
52
-
53
- CREATE TABLE seasons (
54
- series_id Uint64,
55
- season_id Uint64,
56
- title Utf8,
57
- first_aired Date,
58
- last_aired Date,
59
- PRIMARY KEY (series_id, season_id)
60
- );
61
-
62
- CREATE TABLE episodes (
63
- series_id Uint64,
64
- season_id Uint64,
65
- episode_id Uint64,
66
- title Utf8,
67
- air_date Date,
68
- PRIMARY KEY (series_id, season_id, episode_id)
69
- );
70
- " );
71
- });
72
-
73
- response .Status .EnsureSuccess ();
42
+ await queryClient .Exec (@"
43
+ CREATE TABLE series (
44
+ series_id Uint64 NOT NULL,
45
+ title Utf8,
46
+ series_info Utf8,
47
+ release_date Date,
48
+ PRIMARY KEY (series_id)
49
+ );
50
+
51
+ CREATE TABLE seasons (
52
+ series_id Uint64,
53
+ season_id Uint64,
54
+ title Utf8,
55
+ first_aired Date,
56
+ last_aired Date,
57
+ PRIMARY KEY (series_id, season_id)
58
+ );
59
+
60
+ CREATE TABLE episodes (
61
+ series_id Uint64,
62
+ season_id Uint64,
63
+ episode_id Uint64,
64
+ title Utf8,
65
+ air_date Date,
66
+ PRIMARY KEY (series_id, season_id, episode_id)
67
+ );
68
+ " );
74
69
```
75
70
76
71
{% include [ steps/03_write_queries.md] ( steps/03_write_queries.md ) %}
77
72
78
73
Code snippet for data insert/update:
79
74
80
75
``` c#
81
- var response = await tableClient .SessionExec (async session =>
82
- {
83
- var query = @"
84
- DECLARE $id AS Uint64;
85
- DECLARE $title AS Utf8;
86
- DECLARE $release_date AS Date;
87
-
88
- UPSERT INTO series (series_id, title, release_date) VALUES
89
- ($id, $title, $release_date);
90
- " ;
91
-
92
- return await session .ExecuteDataQuery (
93
- query : query ,
94
- txControl : TxControl .BeginSerializableRW ().Commit (),
95
- parameters : new Dictionary <string , YdbValue >
96
- {
97
- { " $id" , YdbValue .MakeUint64 (1 ) },
98
- { " $title" , YdbValue .MakeUtf8 (" NewTitle" ) },
99
- { " $release_date" , YdbValue .MakeDate (DateTime .UtcNow ) }
100
- }
101
- );
102
- });
103
-
104
- response .Status .EnsureSuccess ();
76
+ await queryClient .Exec (@"
77
+ UPSERT INTO series (series_id, title, release_date) VALUES
78
+ ($id, $title, $release_date);
79
+ " ,
80
+ new Dictionary <string , YdbValue >
81
+ {
82
+ { " $id" , YdbValue .MakeUint64 (1 ) },
83
+ { " $title" , YdbValue .MakeUtf8 (" NewTitle" ) },
84
+ { " $release_date" , YdbValue .MakeDate (DateTime .UtcNow ) }
85
+ }
86
+ );
105
87
```
106
88
107
- {% include [ pragmatablepathprefix.md] ( auxilary/pragmatablepathprefix.md ) %}
108
-
109
89
{% include [ steps/04_query_processing.md] ( steps/04_query_processing.md ) %}
110
90
111
- To execute YQL queries, use the ` Session.executeDataQuery() ` method. The SDK lets you explicitly control the execution of transactions and configure the transaction execution mode using the ` TxControl ` class . In the code snippet below, a transaction with the ` SerializableRW ` mode and an automatic commit after executing the request is used. The values of the request parameters are passed in the form of a dictionary name-value in the ` parameters ` argument.
91
+ To execute YQL queries, use the ` queryClient.ReadRow ` или ` queryClient.ReadAllRows ` method. The SDK lets you explicitly control the execution of transactions and configure the transaction execution mode using the ` TxMode ` enum . In the code snippet below, a transaction with the ` NoTx ` mode and an automatic commit after executing the request is used. The values of the request parameters are passed in the form of a dictionary name-value in the ` parameters ` argument.
112
92
113
93
``` c#
114
- var response = await tableClient .SessionExec (async session =>
115
- {
116
- var query = @"
117
- DECLARE $id AS Uint64;
118
-
94
+ var row = await queryClient .ReadRow (@"
119
95
SELECT
120
96
series_id,
121
97
title,
122
98
release_date
123
99
FROM series
124
100
WHERE series_id = $id;
125
- " ;
126
-
127
- return await session .ExecuteDataQuery (
128
- query : query ,
129
- txControl : TxControl .BeginSerializableRW ().Commit (),
130
- parameters : new Dictionary <string , YdbValue >
131
- {
132
- { " $id" , YdbValue .MakeUint64 (id ) }
133
- },
134
- );
135
- });
136
-
137
- response .Status .EnsureSuccess ();
138
- var queryResponse = (ExecuteDataQueryResponse )response ;
139
- var resultSet = queryResponse .Result .ResultSets [0 ];
101
+ " ,
102
+ new Dictionary <string , YdbValue >
103
+ {
104
+ { " $id" , YdbValue .MakeUint64 (id ) }
105
+ }
106
+ );
140
107
```
141
108
142
109
{% include [ steps/05_results_processing.md] ( steps/05_results_processing.md ) %}
@@ -153,35 +120,19 @@ foreach (var row in resultSet.Rows)
153
120
}
154
121
```
155
122
156
-
157
-
158
123
{% include [ scan_query.md] ( steps/08_scan_query.md ) %}
159
124
160
125
``` c#
161
- public void executeScanQuery ()
162
- {
163
- var scanStream = TableClient .ExecuteScanQuery (@$"
164
- SELECT series_id, season_id, COUNT(*) AS episodes_count
165
- FROM episodes
166
- GROUP BY series_id, season_id
167
- ORDER BY series_id, season_id;
168
- " );
169
-
170
- while (await scanStream .Next ())
171
- {
172
- scanStream .Response .EnsureSuccess ();
173
-
174
- var resultSet = scanStream .Response .Result .ResultSetPart ;
175
- if (resultSet != null )
126
+ await queryClient .Stream (
127
+ $" SELECT title FROM seasons ORDER BY series_id, season_id;" ,
128
+ async stream =>
176
129
{
177
- foreach (var row in resultSet .Rows )
178
- {
179
- Console .WriteLine ($" > ScanQuery, " +
180
- $" series_id: {(ulong )row [" series_id" ]}, " +
181
- $" season_id: {(ulong ?)row [" season_id" ]}, " +
182
- $" episodes_count: {(ulong )row [" episodes_count" ]}" );
183
- }
184
- }
185
- }
186
- }
130
+ await foreach (var part in stream )
131
+ {
132
+ foreach (var row in part .ResultSet ! .Rows )
133
+ {
134
+ Console .WriteLine (row [0 ].GetOptionalUtf8 ());
135
+ }
136
+ }
137
+ });
187
138
```
0 commit comments