adding azure table client module

This commit is contained in:
2024-08-11 18:24:01 -05:00
parent ff8aaba741
commit cf1da606d4
7 changed files with 120 additions and 2 deletions

View File

@@ -0,0 +1 @@
export const TABLE_OPTIONS = 'TABLE_OPTIONS';

View File

@@ -0,0 +1,5 @@
export interface TableOptions {
accountName: string;
accountKey: string;
tableName: string;
}

View File

@@ -0,0 +1,21 @@
import { Module, DynamicModule } from '@nestjs/common';
import { TableService } from './az-table.service';
import { TableOptions } from './az-table.interface';
import { TABLE_OPTIONS } from './az-table.constants';
@Module({})
export class TablesModule {
static register(options: TableOptions): DynamicModule {
return {
module: TablesModule,
providers: [
{
provide: TABLE_OPTIONS,
useValue: options
},
TablesModule
],
exports: [TableService]
}
}
}

View File

@@ -0,0 +1,19 @@
import { Inject, Injectable } from '@nestjs/common';
import { TableOptions } from './az-table.interface';
import { TABLE_OPTIONS } from './az-table.constants';
import { TableClient, AzureNamedKeyCredential } from '@azure/data-tables';
@Injectable()
export class TableService {
constructor(
@Inject(TABLE_OPTIONS)
private tablesOptions: TableOptions
) {}
async getTableClient(): Promise<TableClient> {
const credential: AzureNamedKeyCredential = new AzureNamedKeyCredential(this.tablesOptions.accountName, this.tablesOptions.accountKey);
const tableClient: TableClient = new TableClient(`https://${this.tablesOptions.accountName}`, this.tablesOptions.tableName, credential);
return tableClient;
}
}

View File

@@ -3,6 +3,11 @@
export * from './azAppConfig/az-app-config.module';
export * from './azAppConfig/az-app-config.service';
// Azure Data Tables
export * from './azTable/az-table.module';
export * from './azTable/az-table.service';
// Auth
export * from './auth/auth.module';