Skip to content

Commit 83bc37a

Browse files
committed
fix(elysia): add execut
1 parent e2ee0bd commit 83bc37a

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

frameworks/TypeScript/elysia/bun.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"postgres": "^3.4.5",
99
},
1010
"devDependencies": {
11-
"@types/bun": "^1.2.2",
11+
"@types/bun": "^1.2.4",
1212
"typescript": "^5.7.2",
1313
},
1414
},

frameworks/TypeScript/elysia/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"module": "src/index.js",
55
"devDependencies": {
6-
"@types/bun": "^1.2.2",
6+
"@types/bun": "^1.2.4",
77
"typescript": "^5.7.2"
88
},
99
"scripts": {

frameworks/TypeScript/elysia/src/db-handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export const dbHandlers = new Elysia()
5151
// ? Mark as async for Promise result to prevent double Elysia's mapResponse execution
5252
.get("/queries", async (c) => {
5353
const num = parseQueriesNumber(c.query.queries);
54-
const worldPromises = new Array(num);
5554

55+
const worldPromises = new Array(num);
5656
for (let i = 0; i < num; i++) worldPromises[i] = find(rand());
5757

5858
return Promise.all(worldPromises);

frameworks/TypeScript/elysia/src/postgres.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,27 @@ const sql = new SQL({
88
});
99

1010
export const fortunes = () =>
11-
sql`SELECT id, message FROM fortune` as Promise<Fortune>;
11+
sql`SELECT id, message FROM fortune`.execute() as Promise<Fortune[]>;
1212

1313
export const find = (id: number) =>
14-
sql`SELECT id, randomNumber FROM world WHERE id = ${id}`.then(
15-
(arr) => arr[0],
16-
) as Promise<World[]>;
14+
sql`SELECT id, randomNumber FROM world WHERE id = ${id}`
15+
.execute()
16+
.then((arr) => arr[0]) as Promise<World[]>;
1717

1818
export const findThenRand = (id: number) =>
19-
sql`SELECT id, randomNumber FROM world WHERE id = ${id}`.then((arr) => {
20-
arr[0].randomNumber = rand();
21-
return arr[0];
22-
}) as Promise<World[]>;
19+
sql`SELECT id, randomNumber FROM world WHERE id = ${id}`
20+
.execute()
21+
.then((arr) => {
22+
arr[0].randomNumber = rand();
23+
return arr[0];
24+
}) as Promise<World[]>;
2325

2426
export const bulkUpdate = (worlds: World[]) => {
2527
const values = new Array(worlds.length);
2628
for (let i = 0; i < worlds.length; i++)
27-
values[i] = [+worlds[i].id, +worlds[i].randomNumber];
29+
values[i] = [worlds[i].id, worlds[i].randomNumber];
2830

2931
return sql`UPDATE world SET randomNumber = update_data.randomNumber
3032
FROM (VALUES ${sql(values)}) AS update_data (id, randomNumber)
31-
WHERE world.id = update_data.id`;
33+
WHERE world.id = update_data.id`.execute();
3234
};

0 commit comments

Comments
 (0)