Skip to content

Commit

Permalink
Allow passing null as postgres options and use the default
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Feb 1, 2023
1 parent da47a69 commit b37022b
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/Postgres/src/Eventuous.Postgresql/PostgresStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Eventuous.Diagnostics;
using Eventuous.Postgresql.Extensions;
using Eventuous.Tools;
using Microsoft.Extensions.Options;
using Npgsql;
using NpgsqlTypes;

Expand All @@ -26,16 +27,24 @@ public class PostgresStore : IEventStore {

public PostgresStore(
GetPostgresConnection getConnection,
PostgresStoreOptions options,
PostgresStoreOptions? options,
IEventSerializer? serializer = null,
IMetadataSerializer? metaSerializer = null
) {
_serializer = serializer ?? DefaultEventSerializer.Instance;
_metaSerializer = metaSerializer ?? DefaultMetadataSerializer.Instance;
_getConnection = Ensure.NotNull(getConnection, "Connection factory");
_schema = new Schema(options.Schema);
var pgOptions = options ?? new PostgresStoreOptions();
_schema = new Schema(pgOptions.Schema);
}

public PostgresStore(
GetPostgresConnection getConnection,
IOptions<PostgresStoreOptions> options,
IEventSerializer? serializer = null,
IMetadataSerializer? metaSerializer = null
) : this(getConnection, options.Value, serializer, metaSerializer) { }

const string ContentType = "application/json";

async Task<NpgsqlConnection> OpenConnection(CancellationToken cancellationToken) {
Expand Down Expand Up @@ -133,15 +142,13 @@ public Task TruncateStream(
StreamTruncatePosition truncatePosition,
ExpectedStreamVersion expectedVersion,
CancellationToken cancellationToken
)
=> throw new NotImplementedException();
) => throw new NotImplementedException();

public Task DeleteStream(
StreamName stream,
ExpectedStreamVersion expectedVersion,
CancellationToken cancellationToken
)
=> throw new NotImplementedException();
) => throw new NotImplementedException();

StreamEvent ToStreamEvent(PersistedEvent evt) {
var deserialized = _serializer.DeserializeEvent(
Expand All @@ -162,9 +169,14 @@ StreamEvent ToStreamEvent(PersistedEvent evt) {
_ => throw new Exception("Unknown deserialization result")
};

StreamEvent AsStreamEvent(object payload)
=> new(evt.MessageId, payload, meta ?? new Metadata(), ContentType, evt.StreamPosition);
StreamEvent AsStreamEvent(object payload) => new(
evt.MessageId,
payload,
meta ?? new Metadata(),
ContentType,
evt.StreamPosition
);
}
}

record NewPersistedEvent(Guid MessageId, string MessageType, string JsonData, string? JsonMetadata);
record NewPersistedEvent(Guid MessageId, string MessageType, string JsonData, string? JsonMetadata);

0 comments on commit b37022b

Please sign in to comment.