/* * Copyright (c) Microsoft Corporation. * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; import { setContinuationToken } from "../pagingHelper"; import { DatabaseSchemas } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { SqlManagementClient } from "../sqlManagementClient"; import { DatabaseSchema, DatabaseSchemasListByDatabaseNextOptionalParams, DatabaseSchemasListByDatabaseOptionalParams, DatabaseSchemasListByDatabaseResponse, DatabaseSchemasGetOptionalParams, DatabaseSchemasGetResponse, DatabaseSchemasListByDatabaseNextResponse } from "../models"; /// /** Class containing DatabaseSchemas operations. */ export class DatabaseSchemasImpl implements DatabaseSchemas { private readonly client: SqlManagementClient; /** * Initialize a new instance of the class DatabaseSchemas class. * @param client Reference to the service client */ constructor(client: SqlManagementClient) { this.client = client; } /** * List database schemas * @param resourceGroupName The name of the resource group that contains the resource. You can obtain * this value from the Azure Resource Manager API or the portal. * @param serverName The name of the server. * @param databaseName The name of the database. * @param options The options parameters. */ public listByDatabase( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabaseSchemasListByDatabaseOptionalParams ): PagedAsyncIterableIterator { const iter = this.listByDatabasePagingAll( resourceGroupName, serverName, databaseName, options ); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: (settings?: PageSettings) => { if (settings?.maxPageSize) { throw new Error("maxPageSize is not supported by this operation."); } return this.listByDatabasePagingPage( resourceGroupName, serverName, databaseName, options, settings ); } }; } private async *listByDatabasePagingPage( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabaseSchemasListByDatabaseOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: DatabaseSchemasListByDatabaseResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByDatabase( resourceGroupName, serverName, databaseName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByDatabaseNext( resourceGroupName, serverName, databaseName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listByDatabasePagingAll( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabaseSchemasListByDatabaseOptionalParams ): AsyncIterableIterator { for await (const page of this.listByDatabasePagingPage( resourceGroupName, serverName, databaseName, options )) { yield* page; } } /** * List database schemas * @param resourceGroupName The name of the resource group that contains the resource. You can obtain * this value from the Azure Resource Manager API or the portal. * @param serverName The name of the server. * @param databaseName The name of the database. * @param options The options parameters. */ private _listByDatabase( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabaseSchemasListByDatabaseOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, options }, listByDatabaseOperationSpec ); } /** * Get database schema * @param resourceGroupName The name of the resource group that contains the resource. You can obtain * this value from the Azure Resource Manager API or the portal. * @param serverName The name of the server. * @param databaseName The name of the database. * @param schemaName The name of the schema. * @param options The options parameters. */ get( resourceGroupName: string, serverName: string, databaseName: string, schemaName: string, options?: DatabaseSchemasGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, schemaName, options }, getOperationSpec ); } /** * ListByDatabaseNext * @param resourceGroupName The name of the resource group that contains the resource. You can obtain * this value from the Azure Resource Manager API or the portal. * @param serverName The name of the server. * @param databaseName The name of the database. * @param nextLink The nextLink from the previous successful call to the ListByDatabase method. * @param options The options parameters. */ private _listByDatabaseNext( resourceGroupName: string, serverName: string, databaseName: string, nextLink: string, options?: DatabaseSchemasListByDatabaseNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, nextLink, options }, listByDatabaseNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listByDatabaseOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DatabaseSchemaListResult }, default: {} }, queryParameters: [Parameters.filter1, Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DatabaseSchema }, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.schemaName ], headerParameters: [Parameters.accept], serializer }; const listByDatabaseNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DatabaseSchemaListResult }, default: {} }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer };