Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
vgantchev committed Jul 18, 2023
1 parent 3858d84 commit d8a8c5e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
10 changes: 8 additions & 2 deletions clients/sql.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import PG from "pg";
import { sqlPort, sqlHost, sqlUser, sqlPass, sqlDatabase } from "../variables.mjs";
import {
sqlPort,
sqlHost,
sqlUser,
sqlPass,
sqlDatabase,
} from "../variables.mjs";

export async function newSqlClient() {
const pool = new PG.Pool({
Expand All @@ -8,7 +14,7 @@ export async function newSqlClient() {
user: sqlUser(),
password: sqlPass(),
database: sqlDatabase(),
max: 22
max: 22,
});

const client = await pool.connect();
Expand Down
13 changes: 3 additions & 10 deletions helpers/cache_helpers.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { newRedisClient } from "../clients/redis.mjs";
import { newSqlClient } from "../clients/sql.mjs";

export async function readSqlCacheOrUpdate(
cacheSetting,
qry,
) {
export async function readSqlCacheOrUpdate(cacheSetting, qry) {
const redisClient = await newRedisClient();

let cachedResult = await redisClient.get(cacheSetting.key);
Expand All @@ -16,17 +13,13 @@ export async function readSqlCacheOrUpdate(
return cachedResult;
}

export async function updateSqlCache(
cacheSetting,
qry,
redisClient = null
) {
export async function updateSqlCache(cacheSetting, qry, redisClient = null) {
if (redisClient == null) {
redisClient = await newRedisClient();
}

const sqlClient = await newSqlClient();

const { rows } = await sqlClient.query(qry);
const cachedResult = JSON.stringify(rows);

Expand Down
2 changes: 1 addition & 1 deletion variables.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const sqlHost = () => {
} else {
return "127.0.0.1";
}
}
};

// TODO: move to env
export const sqlPort = () => 5432;
Expand Down

0 comments on commit d8a8c5e

Please sign in to comment.