This repository was archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
ReadStreamHeadPosition/Version #391
Merged
yreynhout
merged 3 commits into
SQLStreamStore:master
from
yreynhout:read-stream-head-position-and-version
May 24, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,20 @@ public async Task<long> ReadHeadPosition(CancellationToken cancellationToken = d | |
| return headPosition; | ||
| } | ||
|
|
||
| public async Task<long> ReadStreamHeadPosition(StreamId streamId, CancellationToken cancellationToken = default) | ||
| { | ||
| GuardAgainstDisposed(); | ||
|
|
||
| return (await ReadStreamBackwards(streamId, StreamVersion.End, 1, false, cancellationToken)).LastStreamPosition; | ||
| } | ||
|
|
||
| public async Task<int> ReadStreamHeadVersion(StreamId streamId, CancellationToken cancellationToken = default) | ||
| { | ||
| GuardAgainstDisposed(); | ||
|
|
||
| return (await ReadStreamBackwards(streamId, StreamVersion.End, 1, false, cancellationToken)).LastStreamVersion; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this could be solved in a more optimized way for the http provider, please show me how. |
||
| } | ||
|
|
||
| private static void ThrowOnError(IHalClient client) | ||
| { | ||
| switch(client.StatusCode ?? default) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| using SqlStreamStore.Imports.Ensure.That; | ||
| using SqlStreamStore.Infrastructure; | ||
| using SqlStreamStore.ScriptsV2; | ||
| using SqlStreamStore.Streams; | ||
| using SqlStreamStore.Subscriptions; | ||
|
|
||
| /// <summary> | ||
|
|
@@ -280,13 +281,63 @@ protected override async Task<long> ReadHeadPositionInternal(CancellationToken c | |
|
|
||
| if(result == DBNull.Value) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've left this in - but the test for the new operations seem to suggest this path will never be hit (since result is either |
||
| { | ||
| return -1; | ||
| return Position.End; | ||
| } | ||
| return (long) result; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected override async Task<long> ReadStreamHeadPositionInternal(string streamId, CancellationToken cancellationToken) | ||
| { | ||
| GuardAgainstDisposed(); | ||
|
|
||
| using(var connection = _createConnection()) | ||
| { | ||
| await connection.OpenAsync(cancellationToken).NotOnCapturedContext(); | ||
|
|
||
| using(var command = new SqlCommand(_scripts.ReadStreamHeadPosition, connection)) | ||
| { | ||
| command.CommandTimeout = _commandTimeout; | ||
| command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = new StreamIdInfo(streamId).SqlStreamId.Id }); | ||
| var result = await command | ||
| .ExecuteScalarAsync(cancellationToken) | ||
| .NotOnCapturedContext(); | ||
|
|
||
| if(result == null) | ||
| { | ||
| return Position.End; | ||
| } | ||
| return (long) result; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected override async Task<int> ReadStreamHeadVersionInternal(string streamId, CancellationToken cancellationToken) | ||
| { | ||
| GuardAgainstDisposed(); | ||
|
|
||
| using(var connection = _createConnection()) | ||
| { | ||
| await connection.OpenAsync(cancellationToken).NotOnCapturedContext(); | ||
|
|
||
| using(var command = new SqlCommand(_scripts.ReadStreamHeadVersion, connection)) | ||
| { | ||
| command.CommandTimeout = _commandTimeout; | ||
| command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = new StreamIdInfo(streamId).SqlStreamId.Id }); | ||
| var result = await command | ||
| .ExecuteScalarAsync(cancellationToken) | ||
| .NotOnCapturedContext(); | ||
|
|
||
| if(result == null) | ||
| { | ||
| return StreamVersion.End; | ||
| } | ||
| return (int) result; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected override void Dispose(bool disposing) | ||
| { | ||
| if(disposing) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/SqlStreamStore.MsSql/ScriptsV2/ReadStreamHeadPosition.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| SELECT dbo.Streams.Position | ||
| FROM dbo.Streams | ||
| WHERE dbo.Streams.Id = @streamId |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| SELECT dbo.Streams.[Version] | ||
| FROM dbo.Streams | ||
| WHERE dbo.Streams.Id = @streamId |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/SqlStreamStore.MsSql/ScriptsV3/ReadStreamHeadPosition.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| SELECT dbo.Streams.Position | ||
| FROM dbo.Streams | ||
| WHERE dbo.Streams.Id = @streamId |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| SELECT dbo.Streams.[Version] | ||
| FROM dbo.Streams | ||
| WHERE dbo.Streams.Id = @streamId |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/SqlStreamStore.MySql/MySqlScripts/ReadStreamHeadPosition.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| DROP PROCEDURE IF EXISTS read_stream_head_position; | ||
|
|
||
| CREATE PROCEDURE read_stream_head_position(_stream_id CHAR(42)) | ||
|
|
||
| BEGIN | ||
| SELECT streams.position | ||
| FROM streams | ||
| WHERE streams.id = _stream_id; | ||
| END; |
9 changes: 9 additions & 0 deletions
9
src/SqlStreamStore.MySql/MySqlScripts/ReadStreamHeadVersion.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| DROP PROCEDURE IF EXISTS read_stream_head_version; | ||
|
|
||
| CREATE PROCEDURE read_stream_head_version(_stream_id CHAR(42)) | ||
|
|
||
| BEGIN | ||
| SELECT streams.version | ||
| FROM streams | ||
| WHERE streams.id = _stream_id; | ||
| END; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/SqlStreamStore.Postgres/PgSqlScripts/ReadStreamHeadPosition.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| CREATE OR REPLACE FUNCTION __schema__.read_stream_head_position( | ||
| _stream_id CHAR(42) | ||
| ) | ||
| RETURNS BIGINT | ||
| AS $F$ | ||
| BEGIN | ||
| RETURN (SELECT (__schema__.streams.position) FROM __schema__.streams WHERE __schema__.streams.id = _stream_id); | ||
| END; | ||
| $F$ | ||
| LANGUAGE 'plpgsql'; |
10 changes: 10 additions & 0 deletions
10
src/SqlStreamStore.Postgres/PgSqlScripts/ReadStreamHeadVersion.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| CREATE OR REPLACE FUNCTION __schema__.read_stream_head_version( | ||
| _stream_id CHAR(42) | ||
| ) | ||
| RETURNS INT | ||
| AS $F$ | ||
| BEGIN | ||
| RETURN (SELECT (__schema__.streams.version) FROM __schema__.streams WHERE __schema__.streams.id = _stream_id); | ||
| END; | ||
| $F$ | ||
| LANGUAGE 'plpgsql'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this could be solved in a more optimized way for the http provider, please show me how.