-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(javascript/fastify): upgrade deps, removed mongodb (failed w…
…ith updates).
- Loading branch information
1 parent
c83480a
commit 9d36d04
Showing
13 changed files
with
84 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,35 @@ | ||
const knex = require("knex")({ | ||
client: "mysql2", | ||
connection: { | ||
host: "tfb-database", | ||
user: "benchmarkdbuser", | ||
password: "benchmarkdbpass", | ||
database: "hello_world" | ||
} | ||
}); | ||
const { createPool } = require("mariadb"); | ||
|
||
const clientOpts = { | ||
host: process.env.MYSQL_HOST, | ||
user: process.env.MYSQL_USER, | ||
password: process.env.MYSQL_PSWD, | ||
database: process.env.MYSQL_DBNAME, | ||
}; | ||
|
||
const pool = createPool({ ...clientOpts, connectionLimit: 1 }); | ||
const execute = (text, values) => pool.execute(text, values || undefined); | ||
|
||
async function allFortunes() { | ||
return knex("Fortune").select("*"); | ||
return execute("select id, message from fortune", []); | ||
} | ||
|
||
async function getWorld(id) { | ||
return knex("World") | ||
.first() | ||
.where({ id }); | ||
return execute("select id, randomNumber from world where id = ?", [id]).then( | ||
(arr) => arr[0] | ||
); | ||
} | ||
|
||
async function saveWorlds(worlds) { | ||
const updates = []; | ||
|
||
worlds.forEach(world => { | ||
const { id, randomNumber } = world; | ||
|
||
updates.push( | ||
knex("World") | ||
.update({ randomNumber }) | ||
.where({ id }) | ||
); | ||
}); | ||
|
||
return Promise.all(updates); | ||
async function bulkUpdate(worlds) { | ||
const sql = "update world set randomNumber = ? where id = ?"; | ||
const values = worlds | ||
.map((world) => [world.randomnumber, world.id]) | ||
.sort((a, b) => (a[0] < b[0] ? -1 : 1)); | ||
return pool.batch(sql, values); | ||
} | ||
|
||
module.exports = { | ||
getWorld, | ||
saveWorlds, | ||
allFortunes | ||
bulkUpdate, | ||
allFortunes, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,38 @@ | ||
const knex = require("knex")({ | ||
client: "pg", | ||
connection: { | ||
host: "tfb-database", | ||
user: "benchmarkdbuser", | ||
password: "benchmarkdbpass", | ||
database: "hello_world" | ||
} | ||
}); | ||
const postgres = require("postgres"); | ||
|
||
const clientOpts = { | ||
host: process.env.PG_HOST, | ||
user: process.env.PG_USER, | ||
password: process.env.PG_PSWD, | ||
database: process.env.PG_DBNAME, | ||
}; | ||
|
||
const sql = postgres({ ...clientOpts, max: 1 }); | ||
|
||
async function allFortunes() { | ||
return knex("Fortune").select("*"); | ||
return sql`select id, message from fortune`; | ||
} | ||
|
||
async function getWorld(id) { | ||
return knex("World") | ||
.first() | ||
.where({ id }); | ||
return sql`select id, randomNumber from world where id = ${id}`.then( | ||
(arr) => arr[0] | ||
); | ||
} | ||
|
||
async function saveWorlds(worlds) { | ||
const updates = []; | ||
|
||
worlds.forEach(world => { | ||
const { id, randomNumber } = world; | ||
|
||
updates.push( | ||
knex("World") | ||
.update({ randomnumber: randomNumber }) | ||
.where({ id }) | ||
); | ||
}); | ||
async function bulkUpdate(worlds) { | ||
const values = sql( | ||
worlds | ||
.map((world) => [world.id, world.randomnumber]) | ||
.sort((a, b) => (a[0] < b[0] ? -1 : 1)) | ||
); | ||
|
||
return Promise.all(updates); | ||
return sql`update world set randomNumber = (update_data.randomNumber)::int | ||
from (values ${values}) as update_data (id, randomNumber) | ||
where world.id = (update_data.id)::int`; | ||
} | ||
|
||
module.exports = { | ||
getWorld, | ||
saveWorlds, | ||
allFortunes | ||
bulkUpdate, | ||
allFortunes, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
module.exports = { | ||
randomTfbNumber: () => Math.floor(Math.random() * 10000) + 1, | ||
|
||
getQueries: queries => { | ||
getQueries: (queries) => { | ||
return Math.min(Math.max(parseInt(queries) || 1, 1), 500); | ||
}, | ||
|
||
additionalFortune: { | ||
id: 0, | ||
message: "Additional fortune added at request time." | ||
} | ||
message: "Additional fortune added at request time.", | ||
}, | ||
}; |
Oops, something went wrong.