55namespace Thesis \MessageBus \Persistence \Postgres ;
66
77use Amp \Postgres \PostgresLink ;
8- use Amp \Postgres \PostgresTransaction as AmphpPostgresTransaction ;
8+ use Amp \Postgres \PostgresTransaction ;
99use Thesis \MessageBus \Endpoint ;
1010use Thesis \MessageBus \Envelope ;
11+ use Thesis \MessageBus \Persistence \LazyTransaction ;
1112use Thesis \MessageBus \Persistence \Outbox ;
1213use Thesis \MessageBus \Persistence \Storage ;
13- use Thesis \MessageBus \Persistence \LazyTransaction ;
1414
1515/**
1616 * @api
17- * @implements Storage<AmphpPostgresTransaction >
17+ * @implements Storage<PostgresTransaction >
1818 */
1919final class PostgresStorage implements Storage
2020{
2121 public array $ transactionClasses {
22- get {
23- return [AmphpPostgresTransaction::class];
24- }
22+ get => [PostgresTransaction::class];
2523 }
2624
2725 /**
@@ -61,26 +59,30 @@ public function createLazyTransaction(Endpoint $endpoint): LazyTransaction
6159
6260 public function findOutboxes (Endpoint $ endpoint , array $ incomingMessageIds ): array
6361 {
64- $ placeholders = implode ( ' , ' , array_fill ( 0 , count ($ incomingMessageIds ), '? ' )) ;
62+ $ placeholders = str_repeat ( ' ?, ' , \ count ($ incomingMessageIds ) - 1 ) . '? ' ;
6563
6664 $ result = $ this
6765 ->postgres
6866 ->execute (
6967 <<<SQL
70- select incoming_message_id, commands, events, dispatched_at is not null as dispatched
68+ select
69+ incoming_message_id,
70+ commands,
71+ events,
72+ dispatched_at is not null as dispatched
7173 from {$ this ->outboxTable }
7274 where endpoint = ? and incoming_message_id in ( {$ placeholders })
7375 SQL ,
74- [$ endpoint ->toString (), ...$ incomingMessageIds ],
76+ [
77+ $ endpoint ->toString (),
78+ ...$ incomingMessageIds ,
79+ ],
7580 );
7681
7782 $ outboxes = [];
7883
7984 while (null !== $ row = $ result ->fetchRow ()) {
80- /**
81- * @var array{commands: string, events: string, incoming_message_id: non-empty-string, dispatched: bool} $row
82- */
83-
85+ /** @var array{commands: string, events: string, incoming_message_id: non-empty-string, dispatched: bool} $row */
8486 /** @var list<Envelope> $commands */
8587 $ commands = unserialize ($ row ['commands ' ]);
8688 /** @var list<Envelope> $events */
@@ -99,13 +101,15 @@ public function findOutboxes(Endpoint $endpoint, array $incomingMessageIds): arr
99101
100102 public function markOutboxesDispatched (Endpoint $ endpoint , array $ incomingMessageIds ): void
101103 {
102- $ placeholders = implode ( ' , ' , array_fill ( 0 , count ($ incomingMessageIds ), '? ' )) ;
104+ $ placeholders = str_repeat ( ' ?, ' , \ count ($ incomingMessageIds ) - 1 ) . '? ' ;
103105
104106 $ this ->postgres ->execute (
105107 <<<SQL
106108 update {$ this ->outboxTable }
107109 set dispatched_at = now()
108- where endpoint = ? and incoming_message_id = ( {$ placeholders }) and dispatched_at is null
110+ where endpoint = ?
111+ and incoming_message_id in ( {$ placeholders })
112+ and dispatched_at is null
109113 SQL ,
110114 [
111115 $ endpoint ->toString (),
0 commit comments