@@ -4,128 +4,170 @@ open System.Threading
4
4
open SqlStreamStore.Streams
5
5
6
6
module ReadRaw =
7
- let private fromReadVersion : ReadVersion -> int =
7
+ let private fromReadVersionForwards : ReadVersion -> int =
8
8
function
9
- | ReadVersion.Start -> int ( Position.Start)
10
- | ReadVersion.End -> int ( Position.End)
9
+ | ReadVersion.Any -> int ( Position.Start)
11
10
| ReadVersion.SpecificVersion version -> int ( version)
12
11
13
- let private fromStartPositionInclusive : StartPosition -> int64 =
12
+ let private fromReadVersionBackwards : ReadVersion -> int =
14
13
function
15
- | StartPosition.Start -> 0 L
16
- | StartPosition.End -> - 1 L
14
+ | ReadVersion.Any -> int ( Position.End)
15
+ | ReadVersion.SpecificVersion version -> int ( version)
16
+
17
+ let private fromStartPositionInclusiveForwards : StartPosition -> int64 =
18
+ function
19
+ | StartPosition.Any -> 0 L
20
+ | StartPosition.SpecificPosition position -> position
21
+
22
+ let private fromStartPositionInclusiveBackwards : StartPosition -> int64 =
23
+ function
24
+ | StartPosition.Any -> - 1 L
17
25
| StartPosition.SpecificPosition position -> position
18
26
19
- let readFromAllStream ( store : SqlStreamStore.IStreamStore )
20
- ( readingDirection : ReadingDirection )
21
- ( startPositionInclusive : StartPosition )
22
- ( msgCount : int )
23
- : Async < ReadAllPage > =
27
+ let allForwards ( store : SqlStreamStore.IStreamStore )
28
+ ( startPositionInclusive : StartPosition )
29
+ ( msgCount : int )
30
+ : Async < ReadAllPage > =
24
31
async {
25
- return ! match readingDirection with
26
- | ReadingDirection.Forward ->
27
- store.ReadAllForwards( fromStartPositionInclusive startPositionInclusive, msgCount)
28
- | ReadingDirection.Backward ->
29
- store.ReadAllBackwards( fromStartPositionInclusive startPositionInclusive, msgCount)
32
+ return ! store.ReadAllForwards( fromStartPositionInclusiveForwards startPositionInclusive, msgCount)
30
33
|> Async.awaitTaskWithInnerException
31
34
}
32
35
33
- let readFromStream ( store : SqlStreamStore.IStreamStore )
34
- ( readingDirection : ReadingDirection )
35
- ( streamName : string )
36
- ( readVersion : ReadVersion )
37
- ( msgCount : int )
38
- : Async < ReadStreamPage > =
36
+ let allBackwards ( store : SqlStreamStore.IStreamStore )
37
+ ( startPositionInclusive : StartPosition )
38
+ ( msgCount : int )
39
+ : Async < ReadAllPage > =
39
40
async {
40
- return ! match readingDirection with
41
- | ReadingDirection.Forward ->
42
- store.ReadStreamForwards( StreamId( streamName), fromReadVersion readVersion, msgCount)
43
- | ReadingDirection.Backward ->
44
- store.ReadStreamBackwards( StreamId( streamName), fromReadVersion readVersion, msgCount)
41
+ return ! store.ReadAllBackwards( fromStartPositionInclusiveBackwards startPositionInclusive, msgCount)
45
42
|> Async.awaitTaskWithInnerException
46
43
}
47
44
48
- let readFromAllStream ' ( store : SqlStreamStore.IStreamStore )
49
- ( readingDirection : ReadingDirection )
50
- ( startPositionInclusive : StartPosition )
51
- ( msgCount : int )
52
- ( prefetchJson : bool )
53
- : Async < ReadAllPage > =
45
+ let streamForwards ( store : SqlStreamStore.IStreamStore )
46
+ ( streamName : string )
47
+ ( readVersion : ReadVersion )
48
+ ( msgCount : int )
49
+ : Async < ReadStreamPage > =
54
50
async {
55
- return ! match readingDirection with
56
- | ReadingDirection.Forward ->
57
- store.ReadAllForwards( fromStartPositionInclusive startPositionInclusive, msgCount, prefetchJson)
58
- | ReadingDirection.Backward ->
59
- store.ReadAllBackwards
60
- ( fromStartPositionInclusive startPositionInclusive, msgCount, prefetchJson)
51
+ return ! store.ReadStreamForwards( StreamId( streamName), fromReadVersionForwards readVersion, msgCount)
61
52
|> Async.awaitTaskWithInnerException
62
53
}
63
54
64
- let readFromStream ' ( store : SqlStreamStore.IStreamStore )
65
- ( readingDirection : ReadingDirection )
55
+ let streamBackwards ( store : SqlStreamStore.IStreamStore )
66
56
( streamName : string )
67
57
( readVersion : ReadVersion )
68
58
( msgCount : int )
69
- ( prefetchJson : bool )
70
59
: Async < ReadStreamPage > =
71
60
async {
72
- return ! match readingDirection with
73
- | ReadingDirection.Forward ->
74
- store.ReadStreamForwards
75
- ( StreamId( streamName), fromReadVersion readVersion, msgCount, prefetchJson)
76
- | ReadingDirection.Backward ->
77
- store.ReadStreamBackwards
78
- ( StreamId( streamName), fromReadVersion readVersion, msgCount, prefetchJson)
61
+ return ! store.ReadStreamBackwards( StreamId( streamName), fromReadVersionBackwards readVersion, msgCount)
79
62
|> Async.awaitTaskWithInnerException
80
63
}
81
64
82
- let readFromAllStream '' ( store : SqlStreamStore.IStreamStore )
83
- ( readingDirection : ReadingDirection )
65
+ let allForwardsPrefetch ( store : SqlStreamStore.IStreamStore )
84
66
( startPositionInclusive : StartPosition )
85
67
( msgCount : int )
86
68
( prefetchJson : bool )
87
- ( cancellationToken : CancellationToken )
88
69
: Async < ReadAllPage > =
89
70
async {
90
- return ! match readingDirection with
91
- | ReadingDirection.Forward ->
92
- store.ReadAllForwards
93
- ( fromStartPositionInclusive startPositionInclusive,
94
- msgCount,
95
- prefetchJson,
96
- cancellationToken)
97
- | ReadingDirection.Backward ->
98
- store.ReadAllBackwards
99
- ( fromStartPositionInclusive startPositionInclusive,
100
- msgCount,
101
- prefetchJson,
102
- cancellationToken)
71
+ return ! store.ReadAllForwards
72
+ ( fromStartPositionInclusiveForwards startPositionInclusive, msgCount, prefetchJson)
73
+ |> Async.awaitTaskWithInnerException
74
+ }
75
+
76
+ let allBackwardsPrefetch ( store : SqlStreamStore.IStreamStore )
77
+ ( startPositionInclusive : StartPosition )
78
+ ( msgCount : int )
79
+ ( prefetchJson : bool )
80
+ : Async < ReadAllPage > =
81
+ async {
82
+ return ! store.ReadAllBackwards
83
+ ( fromStartPositionInclusiveBackwards startPositionInclusive, msgCount, prefetchJson)
84
+ |> Async.awaitTaskWithInnerException
85
+ }
86
+
87
+ let streamForwardsPrefetch ( store : SqlStreamStore.IStreamStore )
88
+ ( streamName : string )
89
+ ( readVersion : ReadVersion )
90
+ ( msgCount : int )
91
+ ( prefetchJson : bool )
92
+ : Async < ReadStreamPage > =
93
+ async {
94
+ return ! store.ReadStreamForwards
95
+ ( StreamId( streamName), fromReadVersionForwards readVersion, msgCount, prefetchJson)
96
+ |> Async.awaitTaskWithInnerException
97
+ }
98
+
99
+ let streamBackwardsPrefetch ( store : SqlStreamStore.IStreamStore )
100
+ ( streamName : string )
101
+ ( readVersion : ReadVersion )
102
+ ( msgCount : int )
103
+ ( prefetchJson : bool )
104
+ : Async < ReadStreamPage > =
105
+ async {
106
+ return ! store.ReadStreamBackwards
107
+ ( StreamId( streamName), fromReadVersionBackwards readVersion, msgCount, prefetchJson)
108
+ |> Async.awaitTaskWithInnerException
109
+ }
110
+
111
+ let allForwards ' ( store : SqlStreamStore.IStreamStore )
112
+ ( startPositionInclusive : StartPosition )
113
+ ( msgCount : int )
114
+ ( prefetchJson : bool )
115
+ ( cancellationToken : CancellationToken )
116
+ : Async < ReadAllPage > =
117
+ async {
118
+ return ! store.ReadAllForwards
119
+ ( fromStartPositionInclusiveForwards startPositionInclusive,
120
+ msgCount,
121
+ prefetchJson,
122
+ cancellationToken)
123
+ |> Async.awaitTaskWithInnerException
124
+ }
125
+
126
+ let allBackwards ' ( store : SqlStreamStore.IStreamStore )
127
+ ( startPositionInclusive : StartPosition )
128
+ ( msgCount : int )
129
+ ( prefetchJson : bool )
130
+ ( cancellationToken : CancellationToken )
131
+ : Async < ReadAllPage > =
132
+ async {
133
+ return ! store.ReadAllBackwards
134
+ ( fromStartPositionInclusiveBackwards startPositionInclusive,
135
+ msgCount,
136
+ prefetchJson,
137
+ cancellationToken)
138
+ |> Async.awaitTaskWithInnerException
139
+ }
140
+
141
+ let streamForwards ' ( store : SqlStreamStore.IStreamStore )
142
+ ( streamName : string )
143
+ ( readVersion : ReadVersion )
144
+ ( msgCount : int )
145
+ ( prefetchJson : bool )
146
+ ( cancellationToken : CancellationToken )
147
+ : Async < ReadStreamPage > =
148
+ async {
149
+ return ! store.ReadStreamForwards
150
+ ( StreamId( streamName),
151
+ fromReadVersionForwards readVersion,
152
+ msgCount,
153
+ prefetchJson,
154
+ cancellationToken)
103
155
|> Async.awaitTaskWithInnerException
104
156
}
105
157
106
- let readFromStream '' ( store : SqlStreamStore.IStreamStore )
107
- ( readingDirection : ReadingDirection )
158
+ let streamBackwards ' ( store : SqlStreamStore.IStreamStore )
108
159
( streamName : string )
109
160
( readVersion : ReadVersion )
110
161
( msgCount : int )
111
162
( prefetchJson : bool )
112
163
( cancellationToken : CancellationToken )
113
164
: Async < ReadStreamPage > =
114
165
async {
115
- return ! match readingDirection with
116
- | ReadingDirection.Forward ->
117
- store.ReadStreamForwards
118
- ( StreamId( streamName),
119
- fromReadVersion readVersion,
120
- msgCount,
121
- prefetchJson,
122
- cancellationToken)
123
- | ReadingDirection.Backward ->
124
- store.ReadStreamBackwards
125
- ( StreamId( streamName),
126
- fromReadVersion readVersion,
127
- msgCount,
128
- prefetchJson,
129
- cancellationToken)
166
+ return ! store.ReadStreamBackwards
167
+ ( StreamId( streamName),
168
+ fromReadVersionBackwards readVersion,
169
+ msgCount,
170
+ prefetchJson,
171
+ cancellationToken)
130
172
|> Async.awaitTaskWithInnerException
131
173
}
0 commit comments