@@ -11,6 +11,9 @@ namespace DotJEM.Json.Storage2.SqlServer;
11
11
12
12
public class SqlServerStorageArea : IStorageArea
13
13
{
14
+ private const long DEFAULT_SKIP = 0 ;
15
+ private const int DEFAULT_TAKE = 100 ;
16
+
14
17
private readonly SqlServerStorageContext context ;
15
18
private readonly SqlServerAreaStateManager stateManager ;
16
19
@@ -22,32 +25,48 @@ public SqlServerStorageArea(SqlServerStorageContext context, SqlServerAreaStateM
22
25
this . stateManager = stateManager ;
23
26
}
24
27
28
+ public IAsyncEnumerable < StorageObject > GetAsync ( )
29
+ => GetAsync ( DEFAULT_SKIP , DEFAULT_TAKE , CancellationToken . None ) ;
25
30
26
- //private const long DEFAULT_SKIP = 0;
27
- //private const int DEFAULT_TAKE = 100 ;
31
+ public IAsyncEnumerable < StorageObject > GetAsync ( CancellationToken cancellation )
32
+ => GetAsync ( DEFAULT_SKIP , DEFAULT_TAKE , cancellation ) ;
28
33
29
- // public async IAsyncEnumerable<StorageObject> GetAsync()
30
- // => GetAsync(DEFAULT_SKIP , DEFAULT_TAKE, CancellationToken.None);
34
+ public IAsyncEnumerable < StorageObject > GetAsync ( long skip )
35
+ => GetAsync ( skip , DEFAULT_TAKE , CancellationToken . None ) ;
31
36
32
- // public async IAsyncEnumerable<StorageObject> GetAsync(CancellationToken cancellation)
33
- // => GetAsync(DEFAULT_SKIP , DEFAULT_TAKE, cancellation);
37
+ public IAsyncEnumerable < StorageObject > GetAsync ( long skip , CancellationToken cancellation )
38
+ => GetAsync ( skip , DEFAULT_TAKE , cancellation ) ;
34
39
35
- // public async IAsyncEnumerable<StorageObject> GetAsync(long skip)
36
- // => GetAsync(skip, DEFAULT_TAKE , CancellationToken.None);
40
+ public IAsyncEnumerable < StorageObject > GetAsync ( long skip , int take )
41
+ => GetAsync ( skip , take , CancellationToken . None ) ;
37
42
38
- //public async IAsyncEnumerable<StorageObject> GetAsync(long skip, CancellationToken cancellation)
39
- // => GetAsync(skip, DEFAULT_TAKE, cancellation);
43
+ public async IAsyncEnumerable < StorageObject > GetAsync ( long skip , int take , CancellationToken cancellation )
44
+ {
45
+ if ( ! stateManager . Exists )
46
+ yield break ;
40
47
41
- //public async IAsyncEnumerable<StorageObject> GetAsync(long skip, int take)
42
- // => GetAsync(skip, take, CancellationToken.None);
48
+ using ISqlServerCommand cmd = context . CommandFactory . Create (
49
+ SqlTemplates . SelectFromDataTable_Paged ( stateManager . Schema , stateManager . AreaName ) ,
50
+ ( "take" , take ) ,
51
+ ( "skip" , skip ) ) ;
43
52
44
- //public async IAsyncEnumerable<StorageObject> GetAsync(long skip, int take, CancellationToken cancellation)
45
- //{
46
- // if (!stateManager.Exists)
47
- // yield break;
53
+ ISqlServerDataReader < StorageObject > read = await cmd
54
+ . ExecuteReaderAsync (
55
+ [ "Id" , "ContentType" , "Version" , "Created" , "Updated" , "CreatedBy" , "UpdatedBy" , "Data" ] ,
56
+ values => new StorageObject (
57
+ ( string ) values [ 1 ] ,
58
+ ( Guid ) values [ 0 ] ,
59
+ ( int ) values [ 2 ] ,
60
+ ( DateTime ) values [ 3 ] ,
61
+ ( DateTime ) values [ 4 ] ,
62
+ ( string ) values [ 5 ] ,
63
+ ( string ) values [ 6 ] ,
64
+ JObject . Parse ( ( string ) values [ 7 ] ) ) ,
65
+ CancellationToken . None ) ;
48
66
49
- // throw new NotImplementedException();
50
- //}
67
+ await foreach ( StorageObject obj in read )
68
+ yield return obj ;
69
+ }
51
70
52
71
53
72
@@ -58,11 +77,11 @@ public SqlServerStorageArea(SqlServerStorageContext context, SqlServerAreaStateM
58
77
{
59
78
if ( ! stateManager . Exists )
60
79
return null ;
80
+
61
81
using ISqlServerCommand cmd = context . CommandFactory . Create (
62
82
SqlTemplates . SelectFromDataTable_Byid ( stateManager . Schema , stateManager . AreaName ) ,
63
83
( "id" , id ) ) ;
64
84
65
-
66
85
using ISqlServerDataReader < StorageObject > read = await cmd
67
86
. ExecuteReaderAsync (
68
87
[ "Id" , "ContentType" , "Version" , "Created" , "Updated" , "CreatedBy" , "UpdatedBy" , "Data" ] ,
0 commit comments