forked from event-driven-io/Blumchen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allowed message table customization:
table name, columns names and dimension of varchar column
- Loading branch information
1 parent
4941d3b
commit 1f4aa7a
Showing
16 changed files
with
208 additions
and
96 deletions.
There are no files selected for viewing
This file contains 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 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,76 @@ | ||
using Blumchen.Subscriptions; | ||
using NpgsqlTypes; | ||
|
||
namespace Blumchen; | ||
|
||
#pragma warning disable CS1591 | ||
public record TableDescriptorBuilder | ||
{ | ||
private MessageTable TableDescriptor { get; set; } = new(); | ||
|
||
public MessageTable Build() => TableDescriptor.Build(); | ||
|
||
public TableDescriptorBuilder Name(string eventsTable) | ||
{ | ||
TableDescriptor = new MessageTable(eventsTable); | ||
return this; | ||
} | ||
|
||
public TableDescriptorBuilder Id(string name) | ||
{ | ||
TableDescriptor = TableDescriptor with { Id = new Column.Id(name) }; | ||
return this; | ||
} | ||
|
||
public TableDescriptorBuilder MessageData(string name, MimeType mime) | ||
{ | ||
TableDescriptor = TableDescriptor with { Data = new Column.Data(name), MimeType = mime }; | ||
return this; | ||
} | ||
|
||
public TableDescriptorBuilder MessageType(string name, int dimension = 250) | ||
{ | ||
TableDescriptor = TableDescriptor with { MessageType = new Column.MessageType(name, dimension) }; | ||
return this; | ||
} | ||
|
||
public record MessageTable(string Name = MessageTable.DefaultName) | ||
{ | ||
internal const string DefaultName = "outbox"; | ||
public Column.Id Id { get; internal init; } = Column.Id.Default(); | ||
public Column.MessageType MessageType { get; internal init; } = Column.MessageType.Default(); | ||
public Column.Data Data { get; internal init; } = Column.Data.Default(); | ||
public MimeType MimeType { get; internal init; } = new MimeType.Json(); | ||
public MessageTable Build() => this; | ||
|
||
public override string ToString() => @$" | ||
CREATE TABLE IF NOT EXISTS {Name} ( | ||
{Id} PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, | ||
{MessageType} NOT NULL, | ||
{Data} NOT NULL | ||
);"; | ||
} | ||
|
||
public record Column(string Name, NpgsqlDbType Type) | ||
{ | ||
public override string ToString() => $"{Name} {Type}"; | ||
|
||
public record Id(string Name): Column(Name, NpgsqlDbType.Bigint) | ||
{ | ||
public override string ToString() => base.ToString(); | ||
internal static readonly Func<Id> Default = () => new("id"); | ||
} | ||
|
||
public record MessageType(string Name, int Dimension): Column(Name, NpgsqlDbType.Varchar) | ||
{ | ||
internal static readonly Func<MessageType> Default = () => new("message_type", 250); | ||
public override string ToString() => $"{base.ToString()}({Dimension})"; | ||
} | ||
|
||
public record Data(string Name): Column(Name, NpgsqlDbType.Jsonb) | ||
{ | ||
internal static readonly Func<Data> Default = () => new("data"); | ||
public override string ToString() => base.ToString(); | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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,7 @@ | ||
namespace Blumchen.Subscriptions; | ||
|
||
#pragma warning disable CS1591 | ||
public abstract record MimeType(string mimeType) | ||
{ | ||
public record Json(): MimeType("application/json"); | ||
} |
This file contains 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 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.