mysql.js 656 B

12345678910111213141516
  1. import { createPool } from "mariadb";
  2. import os from "node:os";
  3. const pool = createPool({
  4. host: "tfb-database",
  5. user: "benchmarkdbuser",
  6. password: "benchmarkdbpass",
  7. database: "hello_world",
  8. connectionLimit: os.availableParallelism()
  9. });
  10. export const fortunes = async () => await pool.execute("SELECT id, message FROM fortune");
  11. export const find = async (id) => await pool.execute("SELECT id, randomnumber FROM world WHERE id = ?", [id]).then((arr) => arr[0]);
  12. export const bulkUpdate = async (worlds) => await Promise.all(worlds.map(world => pool.execute("UPDATE world SET randomnumber = ? WHERE id = ?", [world.randomNumber, world.id])));