Skip to content

Commit

Permalink
Make database connection configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
juffalow committed Sep 15, 2024
1 parent ee0d04f commit a94660c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ SERVICES_TOKEN_TTL=900
SERVICES_TOKEN_AWS_REGION=
SERVICES_TOKEN_AWS_USER_POOL_ID=
SERVICES_TOKEN_AWS_CLIENT_ID=
# ------------------- DATABASE ---------------------
SERVICES_DATABASE_TABLE=
SERVICES_DATABASE_ACCESS_KEY_ID=
SERVICES_DATABASE_SECRET_ACCESS_KEY=
SERVICES_DATABASE_REGION=
SERVICES_DATABASE_ENDPOINT=
# -------------------- STORAGE ---------------------
SERVICES_STORAGE_ACCESS_KEY_ID=
SERVICES_STORAGE_SECRET_ACCESS_KEY=
Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export default {
* 1. DynamoDB
*/
database: {
/**
* @type {string}
*/
tableName: process.env.SERVICES_DATABASE_TABLE_NAME,
accessKeyId: process.env.SERVICES_DATABASE_ACCESS_KEY_ID,
secretAccessKey: process.env.SERVICES_DATABASE_SECRET_ACCESS_KEY,
/**
Expand Down
3 changes: 2 additions & 1 deletion src/repositories/file/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import DynamoDBRepository from './DynamoDBRepository';
import CacheRepository from './CacheRepository';
import config from '../../config';
import services from '../../services';

const container = {
get DynamoDB(): FileRepository {
if (typeof this._dynamoDB === 'undefined') {
this._dynamoDB = new DynamoDBRepository(services.Database, 'aws-upload-service');
this._dynamoDB = new DynamoDBRepository(services.Database, config.services.database.tableName);
}

return this._dynamoDB;
Expand Down

0 comments on commit a94660c

Please sign in to comment.