88
99namespace AdoNet ;
1010
11- public class SloTableContext : SloTableContext < YdbDataSource >
11+ public class SloTableContext ( YdbDataSource client ) : SloTableContextBase
1212{
1313 private readonly AsyncPolicy _policy = Policy . Handle < YdbException > ( exception => exception . IsTransient )
1414 . WaitAndRetryAsync ( 10 , attempt => TimeSpan . FromMilliseconds ( attempt * 10 ) ,
@@ -22,7 +22,7 @@ public class SloTableContext : SloTableContext<YdbDataSource>
2222
2323 protected override string Job => "AdoNet" ;
2424
25- protected override async Task Create ( YdbDataSource client , int operationTimeout )
25+ protected override async Task Create ( int operationTimeout )
2626 {
2727 await using var ydbConnection = await client . OpenConnectionAsync ( ) ;
2828 await new YdbCommand ( ydbConnection )
@@ -34,15 +34,15 @@ protected override async Task Create(YdbDataSource client, int operationTimeout)
3434 PayloadStr Text,
3535 PayloadDouble Double,
3636 PayloadTimestamp Timestamp,
37- PRIMARY KEY (hash, id)
38- )
37+ PRIMARY KEY (Guid, Id)
38+ );
39+ { SloTable . Options }
3940 """ ,
4041 CommandTimeout = operationTimeout
4142 } . ExecuteNonQueryAsync ( ) ;
4243 }
4344
4445 protected override async Task < ( int , StatusCode ) > Save (
45- YdbDataSource dataSource ,
4646 SloTable sloTable ,
4747 int writeTimeout ,
4848 Counter ? errorsTotal = null
@@ -56,7 +56,7 @@ PRIMARY KEY (hash, id)
5656
5757 var policyResult = await _policy . ExecuteAndCaptureAsync ( async _ =>
5858 {
59- await using var ydbConnection = await dataSource . OpenConnectionAsync ( ) ;
59+ await using var ydbConnection = await client . OpenConnectionAsync ( ) ;
6060
6161 var ydbCommand = new YdbCommand ( ydbConnection )
6262 {
@@ -68,15 +68,35 @@ PRIMARY KEY (hash, id)
6868 Parameters =
6969 {
7070 new YdbParameter
71- { DbType = DbType . Guid , ParameterName = "Guid" , Value = sloTable . Guid } ,
71+ {
72+ DbType = DbType . Guid ,
73+ ParameterName = "Guid" ,
74+ Value = sloTable . Guid
75+ } ,
7276 new YdbParameter
73- { DbType = DbType . Int32 , ParameterName = "Id" , Value = sloTable . Id } ,
77+ {
78+ DbType = DbType . Int32 ,
79+ ParameterName = "Id" ,
80+ Value = sloTable . Id
81+ } ,
7482 new YdbParameter
75- { DbType = DbType . String , ParameterName = "PayloadStr" , Value = sloTable . PayloadStr } ,
83+ {
84+ DbType = DbType . String ,
85+ ParameterName = "PayloadStr" ,
86+ Value = sloTable . PayloadStr
87+ } ,
7688 new YdbParameter
77- { DbType = DbType . Double , ParameterName = "PayloadDouble" , Value = sloTable . PayloadDouble } ,
89+ {
90+ DbType = DbType . Double ,
91+ ParameterName = "PayloadDouble" ,
92+ Value = sloTable . PayloadDouble
93+ } ,
7894 new YdbParameter
79- { DbType = DbType . Guid , ParameterName = "PayloadTimestamp" , Value = sloTable . PayloadTimestamp }
95+ {
96+ DbType = DbType . DateTime2 ,
97+ ParameterName = "PayloadTimestamp" ,
98+ Value = sloTable . PayloadTimestamp
99+ }
80100 }
81101 } ;
82102
@@ -89,7 +109,6 @@ PRIMARY KEY (hash, id)
89109 }
90110
91111 protected override async Task < ( int , StatusCode , object ? ) > Select (
92- YdbDataSource dataSource ,
93112 dynamic select ,
94113 int readTimeout ,
95114 Counter ? errorsTotal = null
@@ -105,7 +124,7 @@ PRIMARY KEY (hash, id)
105124 var policyResult = await _policy . ExecuteAndCaptureAsync ( async _ =>
106125 {
107126 attempts ++ ;
108- await using var ydbConnection = await dataSource . OpenConnectionAsync ( ) ;
127+ await using var ydbConnection = await client . OpenConnectionAsync ( ) ;
109128
110129 var ydbCommand = new YdbCommand ( ydbConnection )
111130 {
@@ -127,13 +146,10 @@ PRIMARY KEY (hash, id)
127146 return ( attempts , ( ( YdbException ) policyResult . FinalException ) ? . Code ?? StatusCode . Success , policyResult . Result ) ;
128147 }
129148
130- protected override async Task < int > SelectCount ( YdbDataSource client , string sql )
149+ protected override async Task < int > SelectCount ( string sql )
131150 {
132151 await using var ydbConnection = await client . OpenConnectionAsync ( ) ;
133152
134153 return ( int ) ( await new YdbCommand ( ydbConnection ) { CommandText = sql } . ExecuteScalarAsync ( ) ) ! ;
135154 }
136-
137- protected override YdbDataSource CreateClient ( string connectionString ) =>
138- new ( new YdbConnectionStringBuilder ( connectionString ) { LoggerFactory = ISloContext . Factory } ) ;
139155}
0 commit comments