Skip to content

Commit

Permalink
feat: init db wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
alinarublea committed Oct 19, 2023
1 parent 2418fb3 commit 63e21cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/db-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ import createDynamoDBService from './db.js';
import serviceWrap from './service-wrap.js';

function wrapper(func) {
const region = process.env.AWS_REGION;
if (!region) {
throw Error('Please define region in secrets');
}
return (request, context) => serviceWrap(
func,
request,
context,
{ ...context, region },
'__ow_dynamodb',
createDynamoDBService,
);
Expand Down
6 changes: 3 additions & 3 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { log } from './util.js';
const TABLE_SITES = 'spacecat-site';
const TABLE_AUDITS = 'spacecat-audit-index';

function DB() {
const client = new DynamoDBClient({ region: process.env.REGION });
function DB(context) {
const client = new DynamoDBClient({ region: context.region });
const docClient = DynamoDBDocumentClient.from(client);

/**
Expand Down Expand Up @@ -136,6 +136,6 @@ function DB() {
};
}

const createDynamoDBService = () => DB();
const createDynamoDBService = (context) => DB(context);

export default { createDynamoDBService };

0 comments on commit 63e21cc

Please sign in to comment.