Skip to content

Commit

Permalink
Adjusting the Postgresql lightweight sagas to use JSONB across the board
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Sep 2, 2024
1 parent d1c99b4 commit cb49f97
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Persistence/Wolverine.Postgresql/Sagas/SagaStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text.Json;
using JasperFx.Core.Reflection;
using Npgsql;
using NpgsqlTypes;
using Weasel.Core;
using Weasel.Postgresql;
using Weasel.Postgresql.Tables;
Expand Down Expand Up @@ -81,9 +82,9 @@ public async Task InsertAsync(T saga, DbTransaction transaction, CancellationTok
if (id == null || id.Equals(default(TId))) throw new ArgumentOutOfRangeException(nameof(saga), "You must define the saga id when using the lightweight saga storage");

await ensureStorageExistsAsync(cancellationToken);
await transaction.CreateCommand(_insertSql)
await transaction.CreateCommand(_insertSql).As<NpgsqlCommand>()
.With("id", id)
.With("body", JsonSerializer.SerializeToUtf8Bytes(saga))
.With("body", JsonSerializer.SerializeToUtf8Bytes(saga), NpgsqlDbType.Jsonb)
.ExecuteNonQueryAsync(cancellationToken);

saga.Version = 1;
Expand All @@ -94,9 +95,9 @@ public async Task UpdateAsync(T saga, DbTransaction transaction, CancellationTok
await ensureStorageExistsAsync(cancellationToken);

var id = IdSource(saga);
var count = await transaction.CreateCommand(_updateSql)
var count = await transaction.CreateCommand(_updateSql).As<NpgsqlCommand>()
.With("id", id)
.With("body", JsonSerializer.SerializeToUtf8Bytes(saga))
.With("body", JsonSerializer.SerializeToUtf8Bytes(saga), NpgsqlDbType.Jsonb)
.With("version", saga.Version)
.ExecuteNonQueryAsync(cancellationToken);

Expand Down

0 comments on commit cb49f97

Please sign in to comment.