From 51667103654c667ea65945912f58ff05e36517f3 Mon Sep 17 00:00:00 2001 From: Matthew Huntington Date: Wed, 8 May 2024 23:04:07 -0400 Subject: [PATCH] reorg multiple files --- postgres.js | 13 +++++++++++++ redis.js | 14 ++++++++++++++ server.js | 30 ++---------------------------- 3 files changed, 29 insertions(+), 28 deletions(-) create mode 100644 postgres.js create mode 100644 redis.js diff --git a/postgres.js b/postgres.js new file mode 100644 index 0000000..6eb8139 --- /dev/null +++ b/postgres.js @@ -0,0 +1,13 @@ +import pg from 'pg' + +const connectPostgres = async ()=>{ + const { Client } = pg + const postgres = new Client({ + database:'lepr_stack' + }) + await postgres.connect() + console.log('connected to pg'); + return postgres +} + +export default await connectPostgres() diff --git a/redis.js b/redis.js new file mode 100644 index 0000000..ea10774 --- /dev/null +++ b/redis.js @@ -0,0 +1,14 @@ +import { createClient } from 'redis'; +const connectRedis = async ()=>{ + const redis = createClient({ + password: process.env.REDIS_PWD, + socket: { + host: 'redis-11789.c329.us-east4-1.gce.redns.redis-cloud.com', + port: 11789 + } + }); + await redis.connect(); + console.log('connected to redis'); + return redis +} +export default await connectRedis() diff --git a/server.js b/server.js index 625ce68..005093b 100644 --- a/server.js +++ b/server.js @@ -1,31 +1,5 @@ -import { createClient } from 'redis'; -import pg from 'pg' -const connectRedis = async ()=>{ - const redis = createClient({ - password: process.env.REDIS_PWD, - socket: { - host: 'redis-11789.c329.us-east4-1.gce.redns.redis-cloud.com', - port: 11789 - } - }); - await redis.connect(); - console.log('connected to redis'); - return redis -} - -const redis = await connectRedis() - -const connectPostgres = async ()=>{ - const { Client } = pg - const postgres = new Client({ - database:'lepr_stack' - }) - await postgres.connect() - console.log('connected to pg'); - return postgres -} - -const postgres = await connectPostgres() +import redis from './redis.js' +import postgres from './postgres.js' const runExample = async ()=>{ const results = await postgres.query('SELECT pets.*, people.first_name, people.last_name, people.age AS owner_age FROM pets JOIN people ON pets.owner_id = pets.id')