Skip to content

Commit e8e0b3c

Browse files
davecosecoskardudycz
authored andcommitted
Swapped order of handling event stream and event storage
1 parent c473f94 commit e8e0b3c

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/packages/emmett-sqlite/src/eventStore/schema/appendToStream.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,6 @@ const appendEventsRaw = async (
115115
);
116116
}
117117

118-
const { sqlString, values } = buildEventInsertQuery(
119-
events,
120-
expectedStreamVersion,
121-
streamId,
122-
streamType,
123-
options?.partition?.toString() ?? defaultTag,
124-
);
125-
126-
const returningId = await db.querySingle<{
127-
global_position: string;
128-
} | null>(sqlString, values);
129-
130-
if (returningId?.global_position == null) {
131-
throw new Error('Could not find global position');
132-
}
133-
134-
globalPosition = BigInt(returningId.global_position);
135-
136118
let position: { stream_position: string } | null;
137119

138120
if (expectedStreamVersion === 0n) {
@@ -192,6 +174,24 @@ const appendEventsRaw = async (
192174
};
193175
}
194176
}
177+
178+
const { sqlString, values } = buildEventInsertQuery(
179+
events,
180+
expectedStreamVersion,
181+
streamId,
182+
streamType,
183+
options?.partition?.toString() ?? defaultTag,
184+
);
185+
186+
const returningId = await db.querySingle<{
187+
global_position: string;
188+
} | null>(sqlString, values);
189+
190+
if (returningId?.global_position == null) {
191+
throw new Error('Could not find global position');
192+
}
193+
194+
globalPosition = BigInt(returningId.global_position);
195195
} catch (err: unknown) {
196196
if (isSQLiteError(err) && isOptimisticConcurrencyError(err)) {
197197
return {

0 commit comments

Comments
 (0)