Skip to content

Commit e2e28d6

Browse files
committed
fix(elysia): incorrect /update
1 parent e8057db commit e2e28d6

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

frameworks/TypeScript/elysia/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"compile": "bun build --compile --minify --target bun --outfile server src/index.ts"
1414
},
1515
"dependencies": {
16-
"elysia": "^1.2.6",
16+
"elysia": "^1.2.9",
1717
"postgres": "^3.4.5"
1818
}
1919
}

frameworks/TypeScript/elysia/src/postgres.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ export const findThenRand = (id: number) =>
2525
},
2626
);
2727

28-
export const bulkUpdate = (worlds: World[]) =>
29-
sql`UPDATE world SET randomNumber = (update_data.randomNumber)::int
30-
FROM (VALUES ${worlds
31-
.sort((a, b) => {
32-
if (a.id < b.id) return -1;
28+
export const bulkUpdate = (worlds: World[]) => {
29+
const sorted = worlds.toSorted((a, b) => a.id - b.id);
30+
31+
const values = new Array(sorted.length);
32+
for (let i = 0; i < sorted.length; i++)
33+
values[i] = [sorted[i].id, sorted[i].randomNumber];
3334

34-
return 1;
35-
})
36-
.map((world) => [
37-
world.id,
38-
world.randomNumber,
39-
])}) AS update_data (id, randomNumber)
40-
WHERE world.id = (update_data.id)::int`;
35+
sql`UPDATE world SET randomNumber = (update_data.randomNumber)::int
36+
FROM (VALUES ${values}) AS update_data (id, randomNumber)
37+
WHERE world.id = (update_data.id)::int`;
38+
};

0 commit comments

Comments
 (0)