Created
May 3, 2022 10:59
-
-
Save tanveerprottoy/f1e51bcded14682c295e65f7d9377296 to your computer and use it in GitHub Desktop.
db-control.ops.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { CreateTableCommand, CreateTableInput, DeleteTableCommand, DeleteTableInput, DescribeTableCommand, DescribeTableInput, ListTablesCommand, UpdateTableCommand, UpdateTableInput } from "@aws-sdk/client-dynamodb"; | |
| import { Logger } from "@nestjs/common"; | |
| import { DbClientsInstance } from "./db.clients"; | |
| class DbControlOps { | |
| private static instance: DbControlOps; | |
| private constructor() { | |
| console.log('DbControlOps init'); | |
| if(DbControlOps.instance) { | |
| throw new Error("Error - already initialized"); | |
| } | |
| } | |
| static getInstance(): DbControlOps { | |
| DbControlOps.instance = DbControlOps.instance || new DbControlOps(); | |
| return DbControlOps.instance; | |
| } | |
| create = async ( | |
| params: CreateTableInput | |
| ) => { | |
| try { | |
| return await DbClientsInstance.dbDocumentClient.send( | |
| new CreateTableCommand(params) | |
| ); | |
| } | |
| catch(e) { | |
| Logger.error(e); | |
| } | |
| } | |
| update = async ( | |
| params: UpdateTableInput | |
| ) => { | |
| try { | |
| return await DbClientsInstance.dbDocumentClient.send( | |
| new UpdateTableCommand(params) | |
| ); | |
| } | |
| catch(e) { | |
| Logger.error(e); | |
| } | |
| } | |
| list = async ( | |
| // params: ListTablesInput | |
| ) => { | |
| try { | |
| return await DbClientsInstance.dbDocumentClient.send( | |
| new ListTablesCommand({}) | |
| ); | |
| } | |
| catch(e) { | |
| Logger.error(e); | |
| } | |
| } | |
| describe = async ( | |
| params: DescribeTableInput | |
| ) => { | |
| try { | |
| return await DbClientsInstance.dbDocumentClient.send( | |
| new DescribeTableCommand(params) | |
| ); | |
| } | |
| catch(e) { | |
| Logger.error(e); | |
| } | |
| } | |
| delete = async ( | |
| params: DeleteTableInput | |
| ) => { | |
| try { | |
| return await DbClientsInstance.dbDocumentClient.send( | |
| new DeleteTableCommand(params) | |
| ); | |
| } | |
| catch(e) { | |
| Logger.error(e); | |
| } | |
| } | |
| } | |
| export const DbControlOpsInstance = DbControlOps.getInstance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment