Skip to content

Commit

Permalink
convert camelCase to snake_case
Browse files Browse the repository at this point in the history
  • Loading branch information
rudokemper committed May 7, 2024
1 parent 22f3763 commit 5c7d94c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
19 changes: 9 additions & 10 deletions src/azure_queue_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@ const processQueueMessages = async () => {
}
};

function camelToSnakeCase(str) {
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
}

const writeRenderResult = async (renderResult, message, requestId) => {
if (renderResult) {
console.log(
`Writing render result to database for requestId: ${requestId}`,
);
console.log(`Writing render result to database..`);

let updateDbRenderRequest = `UPDATE ${db_table} SET `;
let params = [];
Expand All @@ -151,8 +153,9 @@ const writeRenderResult = async (renderResult, message, requestId) => {
// add a clause to the SQL query to update the corresponding column
// and add the property value to the parameters array
if (renderResult[key] !== null && renderResult[key] !== undefined) {
// All keys converted to lowercase match the db column names
updateDbRenderRequest += `${key.toLowerCase()} = $${count}, `;
// Convert camelCase to snake_case for db column names
let snakeCaseKey = camelToSnakeCase(key);
updateDbRenderRequest += `${snakeCaseKey} = $${count}, `;
params.push(renderResult[key]);
count++;
}
Expand All @@ -163,14 +166,10 @@ const writeRenderResult = async (renderResult, message, requestId) => {
updateDbRenderRequest += ` WHERE id = $${count}`;
params.push(requestId);

// Let's log the SQL query and parameters for debugging
console.log(updateDbRenderRequest);
console.log(params);

await client.query(updateDbRenderRequest, params);

console.log(
`Render result written to database for requestId: ${requestId}`,
`Render result has successfully been successfully to database!`,
);
}
// Delete message from queue
Expand Down
8 changes: 5 additions & 3 deletions src/generate_resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export const generateMBTiles = async (
outputDir,
outputFilename,
) => {
const tempPath = `${tempDir}/${outputFilename}.mbtiles`;
const outputMBTiles = `${outputFilename}.mbtiles`;
const tempPath = `${tempDir}/${outputMBTiles}`;
console.log(`Generating MBTiles file...`);

let numberOfTiles = 0;
Expand Down Expand Up @@ -211,7 +212,7 @@ export const generateMBTiles = async (
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const outputPath = `${outputDir}/${outputFilename}.mbtiles`;
const outputPath = `${outputDir}/${outputMBTiles}`;

try {
const readStream = fs.createReadStream(tempPath);
Expand Down Expand Up @@ -240,7 +241,8 @@ export const generateMBTiles = async (
// Return with success status
return {
errorMessage: null,
fileLocation: outputPath,
fileLocation: outputDir,
filename: outputMBTiles,
fileSize: fileSize,
numberOfTiles,
};
Expand Down
1 change: 1 addition & 0 deletions src/initiate.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export const initiateRendering = async (
status: "SUCCEEDED",
errorMessage: generateResult.errorMessage,
fileLocation: generateResult.fileLocation,
filename: generateResult.filename,
fileSize: generateResult.fileSize,
numberOfTiles: generateResult.numberOfTiles,
workBegun,
Expand Down

0 comments on commit 5c7d94c

Please sign in to comment.