adding azure table client module (#4)
This commit was merged in pull request #4.
This commit is contained in:
1
libs/modules/src/azTable/az-table.constants.ts
Normal file
1
libs/modules/src/azTable/az-table.constants.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const TABLE_OPTIONS = 'TABLE_OPTIONS';
|
||||
5
libs/modules/src/azTable/az-table.interface.ts
Normal file
5
libs/modules/src/azTable/az-table.interface.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export interface TableOptions {
|
||||
accountName: string;
|
||||
accountKey: string;
|
||||
tableName: string;
|
||||
}
|
||||
21
libs/modules/src/azTable/az-table.module.ts
Normal file
21
libs/modules/src/azTable/az-table.module.ts
Normal 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]
|
||||
}
|
||||
}
|
||||
}
|
||||
19
libs/modules/src/azTable/az-table.service.ts
Normal file
19
libs/modules/src/azTable/az-table.service.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user