1- using System ;
2- using System . Threading . Tasks ;
1+ using Internal ;
2+ using Linq2db . Ydb ;
3+ using Linq2db . Ydb . Internal ;
34using LinqToDB ;
5+ using LinqToDB . Async ;
46using LinqToDB . Data ;
57using LinqToDB . Mapping ;
6- using Internal ;
7- using Linq2db . Ydb . Internal ;
8- using LinqToDB . Async ;
9- using LinqToDB . Internal . DataProvider . Ydb . Internal ;
108
119namespace Linq2db ;
1210
1311public sealed class SloTableContext : SloTableContext < SloTableContext . Linq2dbClient >
1412{
15- protected override string Job => "Linq2DB " ;
13+ protected override string Job => "linq2db " ;
1614
1715 static SloTableContext ( )
1816 {
19- // Включаем ретраи SDK глобально (как и раньше)
20- YdbSdkRetryPolicyRegistration . UseGloballyWithIdempotence (
21- maxAttempts : 10 ,
22- onRetry : ( attempt , ex , delay ) => { /* лог/метрики при желании */ }
23- ) ;
17+ YdbSdkRetryPolicyRegistration . UseGloballyWithIdempotence ( ) ;
18+ DataConnection . AddProviderDetector ( YdbTools . ProviderDetector ) ;
2419 }
2520
26- public sealed class Linq2dbClient
21+ public sealed class Linq2dbClient ( string connectionString )
2722 {
28- private readonly string _connectionString ;
29- public Linq2dbClient ( string connectionString ) => _connectionString = connectionString ;
30- public DataConnection Open ( ) => new DataConnection ( "YDB" , _connectionString ) ;
23+ public DataConnection Open ( ) => new ( new DataOptions ( ) . UseConnectionString ( "YDB" , connectionString ) ) ;
3124 }
3225
3326 protected override Linq2dbClient CreateClient ( Config config ) => new ( config . ConnectionString ) ;
@@ -37,47 +30,39 @@ protected override async Task Create(Linq2dbClient client, int operationTimeout)
3730 await using var db = client . Open ( ) ;
3831 db . CommandTimeout = operationTimeout ;
3932
40- try
41- {
42- await db . ExecuteAsync ( $@ "
43- CREATE TABLE `{ SloTable . Name } ` (
44- Guid Uuid,
45- Id Int32,
46- PayloadStr Text,
47- PayloadDouble Double,
48- PayloadTimestamp Timestamp,
49- PRIMARY KEY (Guid, Id)
50- )" ) ;
51- }
52- catch
53- {
54- // Таблица уже есть — ок
55- }
56-
57- if ( ! string . IsNullOrWhiteSpace ( SloTable . Options ) )
58- await db . ExecuteAsync ( SloTable . Options ) ;
33+
34+ await db . ExecuteAsync ( $@ "
35+ CREATE TABLE `{ SloTable . Name } ` (
36+ Guid Uuid,
37+ Id Int32,
38+ PayloadStr Text,
39+ PayloadDouble Double,
40+ PayloadTimestamp Timestamp,
41+ PRIMARY KEY (Guid, Id)
42+ )" ) ;
43+
44+ await db . ExecuteAsync ( SloTable . Options ) ;
5945 }
6046
61- // ВАЖНО: вернуть >0 при успехе, иначе write-графики будут пустые.
6247 protected override async Task < int > Save ( Linq2dbClient client , SloTable sloTable , int writeTimeout )
6348 {
6449 await using var db = client . Open ( ) ;
6550 db . CommandTimeout = writeTimeout ;
6651
67- var sql = $ @ "
52+ const string sql = @"
6853UPSERT INTO `{SloTable.Name}` (Guid, Id, PayloadStr, PayloadDouble, PayloadTimestamp)
6954VALUES (@Guid, @Id, @PayloadStr, @PayloadDouble, @PayloadTimestamp);" ;
7055
7156 var affected = await db . ExecuteAsync (
7257 sql ,
73- new DataParameter ( "Guid" , sloTable . Guid , DataType . Guid ) ,
74- new DataParameter ( "Id" , sloTable . Id , DataType . Int32 ) ,
75- new DataParameter ( "PayloadStr" , sloTable . PayloadStr , DataType . NVarChar ) ,
76- new DataParameter ( "PayloadDouble" , sloTable . PayloadDouble , DataType . Double ) ,
77- new DataParameter ( "PayloadTimestamp" , sloTable . PayloadTimestamp , DataType . DateTime2 )
58+ new DataParameter ( "Guid" , sloTable . Guid , DataType . Guid ) ,
59+ new DataParameter ( "Id" , sloTable . Id , DataType . Int32 ) ,
60+ new DataParameter ( "PayloadStr" , sloTable . PayloadStr , DataType . NVarChar ) ,
61+ new DataParameter ( "PayloadDouble" , sloTable . PayloadDouble , DataType . Double ) ,
62+ new DataParameter ( "PayloadTimestamp" , sloTable . PayloadTimestamp , DataType . DateTime2 )
7863 ) ;
79-
80- return affected > 0 ? affected : 1 ;
64+
65+ return affected ;
8166 }
8267
8368 protected override async Task < object ? > Select ( Linq2dbClient client , ( Guid Guid , int Id ) select , int readTimeout )
@@ -100,8 +85,8 @@ private sealed class SloRow
10085 {
10186 [ Column ] public Guid Guid { get ; set ; }
10287 [ Column ] public int Id { get ; set ; }
103- [ Column ] public string ? PayloadStr { get ; set ; }
104- [ Column ] public double PayloadDouble { get ; set ; }
88+ [ Column ] public string ? PayloadStr { get ; set ; }
89+ [ Column ] public double PayloadDouble { get ; set ; }
10590 [ Column ] public DateTime PayloadTimestamp { get ; set ; }
10691 }
107- }
92+ }
0 commit comments