Skip to content

Commit

Permalink
Fix elevation database queries
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed Feb 21, 2024
1 parent 4b28594 commit ef26be3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://github.com/UW-Macrostrat/macrostrat-api.git"
},
"scripts": {
"start": "nodemon --watch server.ts --exec ts-node --transpileOnly server.ts",
"start": "nodemon --watch v2 --exec ts-node --transpileOnly server.ts",
"serve": "ts-node --transpileOnly server.ts",
"test": "mocha ./v2",
"defs": "ts-node --transpileOnly ./v2/utilities/validateDefs.ts",
Expand Down
3 changes: 3 additions & 0 deletions v2/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
redis,
cacheRefreshKey,
postgresDatabases = {},
elevationDatabase,
} = require("../credentials.ts");

exports.mysql = mysql;
Expand All @@ -15,3 +16,5 @@ exports.redis = redis;
exports.cacheRefreshKey = cacheRefreshKey;

exports.postgresDatabases = postgresDatabases;

exports.elevationDatabase = elevationDatabase;
23 changes: 16 additions & 7 deletions v2/larkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ var mysql = require("mysql"),
const named = require("yesql").pg;
const { Client, Pool } = require("pg");

const printQueries = true;

(function () {
var larkin = {};

Expand All @@ -33,15 +31,25 @@ const printQueries = true;
larkin.queryPg = function (db, sql, params, callback) {
const nameMapping = credentials.postgresDatabases ?? {};
const dbName = nameMapping[db] ?? db;
console.log(dbName, sql, params);

const pool = new Pool({
connectionString: credentials.pg.connectionString,
});
let connectionString = credentials.pg.connectionString;

if (dbName == "geomacro") {
console.warn(
"In Macrostrat v2, 'geomacro' is merged with 'burwell' into the 'macrostrat' database.",
);
}

if (dbName == "elevation") {
/** Special case for elevation database (temporary) */
connectionString = credentials.elevationDatabase;
}

const pool = new Pool({ connectionString });

pool.connect(function (err, client, done) {
if (err) {
this.log("error", "error connecting - " + err);
larkin.log("error", "error connecting - " + err);
callback(err);
} else {
var query = client.query(sql, params, function (err, result) {
Expand Down Expand Up @@ -75,6 +83,7 @@ const printQueries = true;
};

larkin.query = function (sql, params, callback) {
//console.warn(`Deprecated MySQL query:\n${sql}`);
if (sql.indexOf(":") > -1 && Object.keys(params).length > 0) {
var newQuery = larkin.toUnnamed(sql, params);
sql = newQuery[0];
Expand Down

0 comments on commit ef26be3

Please sign in to comment.