postgres.js 696 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const knex = require("knex")({
  2. client: "pg",
  3. connection: {
  4. host: "tfb-database",
  5. user: "benchmarkdbuser",
  6. password: "benchmarkdbpass",
  7. database: "hello_world"
  8. }
  9. });
  10. async function allFortunes() {
  11. return knex("Fortune").select("*");
  12. }
  13. async function getWorld(id) {
  14. return knex("World")
  15. .first()
  16. .where({ id });
  17. }
  18. async function saveWorlds(worlds) {
  19. const updates = [];
  20. worlds.forEach(world => {
  21. const { id, randomNumber } = world;
  22. updates.push(
  23. knex("World")
  24. .update({ randomnumber: randomNumber })
  25. .where({ id })
  26. );
  27. });
  28. return Promise.all(updates);
  29. }
  30. module.exports = {
  31. getWorld,
  32. saveWorlds,
  33. allFortunes
  34. };