-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
temp changes; may need to debug eventuous pg projector (#47)
- Loading branch information
1 parent
29402a4
commit e922a48
Showing
7 changed files
with
74 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Npgsql; | ||
|
||
namespace Catalog.Api.Infrastructure; | ||
|
||
public static class Postgres | ||
{ | ||
public static NpgsqlDataSource ConfigurePostgres(IConfiguration configuration) | ||
{ | ||
var config = configuration.GetSection("Postgres").Get<PostgresSettings>(); | ||
return new NpgsqlDataSourceBuilder(config!.ConnectionString).Build(); | ||
} | ||
} | ||
|
||
public record PostgresSettings | ||
{ | ||
public string ConnectionString { get; init; } = null!; | ||
public string Schema { get; init; } = null!; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Catalog/Catalog.Api/Queries/Products/ProductPgProjector.cs
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,30 @@ | ||
using Catalog.Products; | ||
using Eventuous.Postgresql.Projections; | ||
using Npgsql; | ||
|
||
namespace Catalog.Api.Queries.Products; | ||
|
||
public class ProductPgProjector : PostgresProjector | ||
{ | ||
public ProductPgProjector(NpgsqlDataSource dataSource) : base(dataSource) | ||
{ | ||
const string insertSql = | ||
""" | ||
insert into catalog.product_drafts | ||
(product_id, sku, brand_name, created_at) | ||
values (@product_id, @sku, @brand_name, @created_at) | ||
"""; | ||
|
||
On<ProductEvents.V1.ProductDrafted>( | ||
(connection, ctx) => | ||
Project( | ||
connection, | ||
insertSql, | ||
new NpgsqlParameter("@product_id", ctx.Stream.GetId()), | ||
new NpgsqlParameter("@sku", ctx.Message.Sku), | ||
new NpgsqlParameter("@brand_name", ctx.Message.Brand), | ||
new NpgsqlParameter("@created_at", ctx.Message.CreatedAt) | ||
) | ||
); | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/Catalog/Catalog.Api/Scripts/create_catalog_product_drafts.sql
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 @@ | ||
create table if not exists catalog.product_drafts | ||
( | ||
product_id varchar(256) not null primary key, | ||
sku varchar(32) not null, | ||
brand_name varchar(128), | ||
created_at timestamp | ||
); |
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 @@ | ||
CREATE SCHEMA IF NOT EXISTS catalog; |
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 @@ | ||
CREATE SCHEMA IF NOT EXISTS eventuous; |
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