Skip to content

Commit 4869889

Browse files
committed
Fix sketchy returnAll with insertIgnoreInto
1 parent 00967f3 commit 4869889

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/service/lootDegradation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ export async function exposeWithRadiation(context: BotContext) {
6363
return;
6464
}
6565

66-
const attribute = await lootService.addLootAttributeIfNotPresent(
66+
const attributeAdded = await lootService.addLootAttributeIfNotPresent(
6767
targetLoot.id,
6868
LootAttributeKindId.RADIOACTIVE,
6969
);
70-
if (!attribute) {
70+
if (!attributeAdded) {
7171
return;
7272
}
7373

src/storage/loot.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,15 @@ export async function getLootAttributes(lootId: LootId, ctx = db()) {
333333
.execute();
334334
}
335335

336+
/**
337+
* Returns `true` if the attribute was added.
338+
*/
336339
export async function addLootAttributeIfNotPresent(
337340
lootId: LootId,
338341
attributeTemplate: LootAttributeTemplate,
339342
ctx = db(),
340343
) {
341-
return await ctx
344+
const r = await ctx
342345
.insertInto("lootAttribute")
343346
.orIgnore()
344347
.values({
@@ -350,6 +353,6 @@ export async function addLootAttributeIfNotPresent(
350353
color: attributeTemplate.color,
351354
deletedAt: null,
352355
})
353-
.returningAll()
354-
.executeTakeFirstOrThrow();
356+
.execute();
357+
return r.length > 0;
355358
}

0 commit comments

Comments
 (0)