Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added LoadAsync to EventStore repository #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Tacta.EventStore/Repository/EventStoreRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,11 @@ public async Task<IReadOnlyCollection<EventStoreRecord<T>>> GetAsync<T>(string q
}
}
}

public async Task<IReadOnlyCollection<EventStoreRecord<T>>> LoadAsync<T>(int offset, int rows, IEnumerable<string> eventsInterestedIn)
{
var param = new { eventT = eventsInterestedIn };
return await GetAsync<T>(StoredEvent.SelectTopOffset(rows, offset), param).ConfigureAwait(false);
}
}
}
1 change: 1 addition & 0 deletions Tacta.EventStore/Repository/IEventStoreRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public interface IEventStoreRepository
Task<IReadOnlyCollection<EventStoreRecord<T>>> GetUntilAsync<T>(string aggregateId, int sequence);
Task<int> GetLatestSequence();
Task<IReadOnlyCollection<EventStoreRecord<T>>> GetAsync<T>(string query, object param);
Task<IReadOnlyCollection<EventStoreRecord<T>>> LoadAsync<T>(int offset, int rows, IEnumerable<string> eventsInterestedIn);
}
}
10 changes: 10 additions & 0 deletions Tacta.EventStore/Repository/StoredEvent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text;

namespace Tacta.EventStore.Repository
{
Expand Down Expand Up @@ -48,5 +49,14 @@ FROM [dbo].[EventStore]

public static string SelectLatestSequenceQuery =
@"SELECT MAX ([Sequence]) FROM [dbo].[EventStore]";

public static string SelectTopOffset(int rows, int offset)
{
var query = new StringBuilder($@"SELECT TOP({rows}) [Id], [AggregateId], [Version], [CreatedAt], [Payload], [Sequence]
FROM [dbo].[EventStore]
WHERE Sequence>{offset} and Name in @eventT order by Sequence ASC");

return query.ToString();
}
}
}