Skip to content

Commit

Permalink
dry db conection
Browse files Browse the repository at this point in the history
  • Loading branch information
squidgetx committed Dec 16, 2022
1 parent c4ccbf7 commit d9042fc
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const logger = require("morgan");
const cors = require("cors");

const auth = require("./lib/auth");

const fetch_tweets = require("./lib/fetch");
const log_tweets = require("./lib/log");

Expand Down
7 changes: 7 additions & 0 deletions server/db/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const pgPromise = require("pg-promise");
const config = require("../lib/config");

const pgp = pgPromise({});
const DB = pgp(config.dbConnectionString);

module.exports = DB;
3 changes: 1 addition & 2 deletions server/db/qualtrics.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Ignore treatment group for now
*/
import { assert } from "console";
import { parse } from "csv-parse/sync";
import fs from "fs";
import decompress from "decompress";

Expand All @@ -13,9 +12,9 @@ import { default as config } from "../lib/config.js";
import pgPromise from "pg-promise";

const pgp = pgPromise({});
import { default as DB } from "./db.js";

// todo fix this
const DB = pgp("postgres://testuser:password@localhost:5432/server-dev");

const downloadSurveyResponses = async function (survey_id) {
console.log("downloading responses from qualtrics...");
Expand Down
3 changes: 1 addition & 2 deletions server/db/scraper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import pgPromise from "pg-promise";

const pgp = pgPromise({});

// todo fix this
const DB = pgp("postgres://testuser:password@localhost:5432/server-dev");
import { default as DB } from "./db.js";

const BEARER_TOKEN = process.env.BEARER_TOKEN;

Expand Down
4 changes: 1 addition & 3 deletions server/lib/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const pgp = require("pg-promise")(/* options */);
const db = pgp("postgres://testuser:password@localhost:5432/server-dev");
// TODO dRy this
const db = require("../db/db.js");

const cache = {};

Expand Down
3 changes: 1 addition & 2 deletions server/lib/fetch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const pgp = require("pg-promise")(/* options */);
const db = pgp("postgres://testuser:password@localhost:5432/server-dev");
const db = require("../db/db.js");

const DUMMY_TWEET = {
text: `All the more so when you consider that Biddle himself then went on to oversee the "Great Sedition Trial" of 1944 (30 fascist and pro-Nazi defendants accused of conspiring with the Hitler government), which also ended in a mistrial...`,
Expand Down

0 comments on commit d9042fc

Please sign in to comment.