Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions frameworks/JavaScript/ultimate-express/database/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import { clientOpts } from '../config.js'

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

const execute = (text, values) => pool.execute(text, values || undefined)

export const fortunes = () => execute('SELECT id, message FROM fortune')
export const fortunes = () => pool.execute('SELECT id, message FROM fortune')

export const find = async(id) => {
const arr = await execute('SELECT id, randomNumber AS randomnumber FROM world WHERE id = ?', [id]);
const arr = await pool.execute('SELECT id, randomNumber AS randomnumber FROM world WHERE id = ?', [id]);
return arr[0];
}

export const getAllWorlds = () => execute('SELECT id, randomNumber AS randomnumber FROM world')
export const getAllWorlds = () => pool.execute('SELECT id, randomNumber AS randomnumber FROM world')

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))
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import postgres from 'postgres'
import { clientOpts } from '../config.js'

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

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

Expand Down
Loading