1+ using System ;
2+ using System . Security . Cryptography . X509Certificates ;
3+ using System . Threading . Tasks ;
4+ using Microsoft . Extensions . Logging ;
5+ using Ydb . Sdk . Auth ;
6+ using Ydb . Sdk . Services . Table ;
7+
8+ namespace Ydb . Sdk . Examples ;
9+
10+ internal partial class BasicExample : TableExampleBase
11+ {
12+ private BasicExample ( TableClient client , string database , string path )
13+ : base ( client , database , path )
14+ {
15+ }
16+
17+ public static async Task Run (
18+ string endpoint ,
19+ string database ,
20+ ICredentialsProvider credentialsProvider ,
21+ X509Certificate ? customServerCertificate ,
22+ string path ,
23+ ILoggerFactory loggerFactory )
24+ {
25+ var config = new DriverConfig (
26+ endpoint : endpoint ,
27+ database : database ,
28+ credentials : credentialsProvider ,
29+ customServerCertificate : customServerCertificate
30+ ) ;
31+
32+ await using var driver = await Driver . CreateInitialized (
33+ config : config ,
34+ loggerFactory : loggerFactory
35+ ) ;
36+
37+ using var tableClient = new TableClient ( driver , new TableClientConfig ( ) ) ;
38+
39+ var example = new BasicExample ( tableClient , database , path ) ;
40+
41+ await example . SchemeQuery ( ) ;
42+ await example . FillData ( ) ;
43+ await example . SimpleSelect ( 1 ) ;
44+ await example . SimpleUpsert ( 10 , "Coming soon" , DateTime . UtcNow ) ;
45+ await example . SimpleSelect ( 10 ) ;
46+ await example . InteractiveTx ( ) ;
47+ await example . ReadTable ( ) ;
48+ await example . ScanQuery ( DateTime . Parse ( "2007-01-01" ) ) ;
49+ }
50+
51+ private static ExecuteDataQuerySettings DefaultDataQuerySettings =>
52+ new ( )
53+ {
54+ // Indicates that client is no longer interested in the result of operation after the
55+ // specified duration starting from the moment when operation arrives at the server.
56+ // Status code TIMEOUT will be returned from server in case when operation result in
57+ // not available in the specified time period. This status code doesn't indicate the result
58+ // of operation, it might be completed or cancelled.
59+ OperationTimeout = TimeSpan . FromSeconds ( 1 ) ,
60+
61+ // Transport timeout from the moment operation was sent to server. It is useful in case
62+ // of possible network issues, to that query doesn't hang forever.
63+ // It is recommended to set this value to a larger value than OperationTimeout to give
64+ // server some time to issue a response.
65+ TransportTimeout = TimeSpan . FromSeconds ( 5 ) ,
66+
67+ // Keep query compilation result in query cache or not. Should be false for ad-hoc queries,
68+ // and true (default) for high-RPS queries.
69+ KeepInQueryCache = false
70+ } ;
71+
72+ private ExecuteDataQuerySettings DefaultCachedDataQuerySettings
73+ {
74+ get
75+ {
76+ var settings = DefaultDataQuerySettings ;
77+ settings . KeepInQueryCache = true ;
78+ return settings ;
79+ }
80+ }
81+ }
0 commit comments