Skip to content

Commit

Permalink
Expose shortcut for table validation when bootstrapping publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
lsfera committed Jul 17, 2024
1 parent c446721 commit e71999b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Blumchen/Publications/PublisherOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
using Blumchen.Database;
using Blumchen.Serialization;
using Npgsql;

namespace Blumchen.Publications;

public record PublisherOptions(TableDescriptorBuilder.MessageTable TableDescriptor, IJsonTypeResolver JsonTypeResolver);

public static class PublisherOptionsExtensions
{
public static async Task<PublisherOptions> EnsureTable(this PublisherOptions publisherOptions, NpgsqlDataSource dataSource, CancellationToken ct)
{
await dataSource.EnsureTableExists(publisherOptions.TableDescriptor, ct);
return publisherOptions;
}

public static Task<PublisherOptions> EnsureTable(this PublisherOptions publisherOptions,
string connectionString, CancellationToken ct)
=> EnsureTable(publisherOptions, new NpgsqlDataSourceBuilder(connectionString).Build(), ct);
}

0 comments on commit e71999b

Please sign in to comment.