Skip to content

Commit 6dedba6

Browse files
authored
ultimate-express: small perf on db layer (#10542)
* perf: disable fetch_types option to postgres connection * perf: avoid additional function call
1 parent deb9eba commit 6dedba6

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

frameworks/JavaScript/ultimate-express/database/mysql.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import { clientOpts } from '../config.js'
44

55
const pool = createPool({ ...clientOpts, connectionLimit: cpus().length })
66

7-
const execute = (text, values) => pool.execute(text, values || undefined)
8-
9-
export const fortunes = () => execute('SELECT id, message FROM fortune')
7+
export const fortunes = () => pool.execute('SELECT id, message FROM fortune')
108

119
export const find = async(id) => {
12-
const arr = await execute('SELECT id, randomNumber AS randomnumber FROM world WHERE id = ?', [id]);
10+
const arr = await pool.execute('SELECT id, randomNumber AS randomnumber FROM world WHERE id = ?', [id]);
1311
return arr[0];
1412
}
1513

16-
export const getAllWorlds = () => execute('SELECT id, randomNumber AS randomnumber FROM world')
14+
export const getAllWorlds = () => pool.execute('SELECT id, randomNumber AS randomnumber FROM world')
1715

1816
export const bulkUpdate = (worlds) => pool.batch('UPDATE world SET randomNumber = ? WHERE id = ?', worlds.map(world => [world.randomNumber, world.id]).sort((a, b) => (a[1] < b[1]) ? -1 : 1))

frameworks/JavaScript/ultimate-express/database/postgres.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import postgres from 'postgres'
22
import { clientOpts } from '../config.js'
33

4-
const sql = postgres({ ...clientOpts, max: 1 })
4+
const sql = postgres({ ...clientOpts, max: 1, fetch_types: false })
55

66
export const fortunes = () => sql`SELECT id, message FROM fortune`
77

0 commit comments

Comments
 (0)