/* * 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 { Databases } 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 { SimplePollerLike, OperationState, createHttpPoller } from "@azure/core-lro"; import { createLroSpec } from "../lroImpl"; import { Metric, DatabasesListMetricsOptionalParams, DatabasesListMetricsResponse, MetricDefinition, DatabasesListMetricDefinitionsOptionalParams, DatabasesListMetricDefinitionsResponse, Database, DatabasesListByServerNextOptionalParams, DatabasesListByServerOptionalParams, DatabasesListByServerResponse, DatabasesListByElasticPoolNextOptionalParams, DatabasesListByElasticPoolOptionalParams, DatabasesListByElasticPoolResponse, DatabasesListInaccessibleByServerNextOptionalParams, DatabasesListInaccessibleByServerOptionalParams, DatabasesListInaccessibleByServerResponse, DatabasesGetOptionalParams, DatabasesGetResponse, DatabasesCreateOrUpdateOptionalParams, DatabasesCreateOrUpdateResponse, DatabasesDeleteOptionalParams, DatabaseUpdate, DatabasesUpdateOptionalParams, DatabasesUpdateResponse, ExportDatabaseDefinition, DatabasesExportOptionalParams, DatabasesExportResponse, DatabasesFailoverOptionalParams, ImportExistingDatabaseDefinition, DatabasesImportOptionalParams, DatabasesImportResponse, ResourceMoveDefinition, DatabasesRenameOptionalParams, DatabasesPauseOptionalParams, DatabasesPauseResponse, DatabasesResumeOptionalParams, DatabasesResumeResponse, DatabasesUpgradeDataWarehouseOptionalParams, DatabasesListByServerNextResponse, DatabasesListByElasticPoolNextResponse, DatabasesListInaccessibleByServerNextResponse } from "../models"; /// /** Class containing Databases operations. */ export class DatabasesImpl implements Databases { private readonly client: SqlManagementClient; /** * Initialize a new instance of the class Databases class. * @param client Reference to the service client */ constructor(client: SqlManagementClient) { this.client = client; } /** * Returns database metrics. * @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 filter An OData filter expression that describes a subset of metrics to return. * @param options The options parameters. */ public listMetrics( resourceGroupName: string, serverName: string, databaseName: string, filter: string, options?: DatabasesListMetricsOptionalParams ): PagedAsyncIterableIterator { const iter = this.listMetricsPagingAll( resourceGroupName, serverName, databaseName, filter, 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.listMetricsPagingPage( resourceGroupName, serverName, databaseName, filter, options, settings ); } }; } private async *listMetricsPagingPage( resourceGroupName: string, serverName: string, databaseName: string, filter: string, options?: DatabasesListMetricsOptionalParams, _settings?: PageSettings ): AsyncIterableIterator { let result: DatabasesListMetricsResponse; result = await this._listMetrics( resourceGroupName, serverName, databaseName, filter, options ); yield result.value || []; } private async *listMetricsPagingAll( resourceGroupName: string, serverName: string, databaseName: string, filter: string, options?: DatabasesListMetricsOptionalParams ): AsyncIterableIterator { for await (const page of this.listMetricsPagingPage( resourceGroupName, serverName, databaseName, filter, options )) { yield* page; } } /** * Returns database metric definitions. * @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 listMetricDefinitions( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesListMetricDefinitionsOptionalParams ): PagedAsyncIterableIterator { const iter = this.listMetricDefinitionsPagingAll( 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.listMetricDefinitionsPagingPage( resourceGroupName, serverName, databaseName, options, settings ); } }; } private async *listMetricDefinitionsPagingPage( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesListMetricDefinitionsOptionalParams, _settings?: PageSettings ): AsyncIterableIterator { let result: DatabasesListMetricDefinitionsResponse; result = await this._listMetricDefinitions( resourceGroupName, serverName, databaseName, options ); yield result.value || []; } private async *listMetricDefinitionsPagingAll( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesListMetricDefinitionsOptionalParams ): AsyncIterableIterator { for await (const page of this.listMetricDefinitionsPagingPage( resourceGroupName, serverName, databaseName, options )) { yield* page; } } /** * Gets a list of databases. * @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 options The options parameters. */ public listByServer( resourceGroupName: string, serverName: string, options?: DatabasesListByServerOptionalParams ): PagedAsyncIterableIterator { const iter = this.listByServerPagingAll( resourceGroupName, serverName, 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.listByServerPagingPage( resourceGroupName, serverName, options, settings ); } }; } private async *listByServerPagingPage( resourceGroupName: string, serverName: string, options?: DatabasesListByServerOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: DatabasesListByServerResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByServer(resourceGroupName, serverName, options); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByServerNext( resourceGroupName, serverName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listByServerPagingAll( resourceGroupName: string, serverName: string, options?: DatabasesListByServerOptionalParams ): AsyncIterableIterator { for await (const page of this.listByServerPagingPage( resourceGroupName, serverName, options )) { yield* page; } } /** * Gets a list of databases in an elastic pool. * @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 elasticPoolName The name of the elastic pool. * @param options The options parameters. */ public listByElasticPool( resourceGroupName: string, serverName: string, elasticPoolName: string, options?: DatabasesListByElasticPoolOptionalParams ): PagedAsyncIterableIterator { const iter = this.listByElasticPoolPagingAll( resourceGroupName, serverName, elasticPoolName, 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.listByElasticPoolPagingPage( resourceGroupName, serverName, elasticPoolName, options, settings ); } }; } private async *listByElasticPoolPagingPage( resourceGroupName: string, serverName: string, elasticPoolName: string, options?: DatabasesListByElasticPoolOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: DatabasesListByElasticPoolResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByElasticPool( resourceGroupName, serverName, elasticPoolName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByElasticPoolNext( resourceGroupName, serverName, elasticPoolName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listByElasticPoolPagingAll( resourceGroupName: string, serverName: string, elasticPoolName: string, options?: DatabasesListByElasticPoolOptionalParams ): AsyncIterableIterator { for await (const page of this.listByElasticPoolPagingPage( resourceGroupName, serverName, elasticPoolName, options )) { yield* page; } } /** * Gets a list of inaccessible databases in a logical server * @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 options The options parameters. */ public listInaccessibleByServer( resourceGroupName: string, serverName: string, options?: DatabasesListInaccessibleByServerOptionalParams ): PagedAsyncIterableIterator { const iter = this.listInaccessibleByServerPagingAll( resourceGroupName, serverName, 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.listInaccessibleByServerPagingPage( resourceGroupName, serverName, options, settings ); } }; } private async *listInaccessibleByServerPagingPage( resourceGroupName: string, serverName: string, options?: DatabasesListInaccessibleByServerOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: DatabasesListInaccessibleByServerResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listInaccessibleByServer( resourceGroupName, serverName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listInaccessibleByServerNext( resourceGroupName, serverName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listInaccessibleByServerPagingAll( resourceGroupName: string, serverName: string, options?: DatabasesListInaccessibleByServerOptionalParams ): AsyncIterableIterator { for await (const page of this.listInaccessibleByServerPagingPage( resourceGroupName, serverName, options )) { yield* page; } } /** * Returns database metrics. * @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 filter An OData filter expression that describes a subset of metrics to return. * @param options The options parameters. */ private _listMetrics( resourceGroupName: string, serverName: string, databaseName: string, filter: string, options?: DatabasesListMetricsOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, filter, options }, listMetricsOperationSpec ); } /** * Returns database metric definitions. * @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 _listMetricDefinitions( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesListMetricDefinitionsOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, options }, listMetricDefinitionsOperationSpec ); } /** * Gets a list of databases. * @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 options The options parameters. */ private _listByServer( resourceGroupName: string, serverName: string, options?: DatabasesListByServerOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, options }, listByServerOperationSpec ); } /** * Gets a database. * @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. */ get( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, options }, getOperationSpec ); } /** * Creates a new database or updates an existing database. * @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 parameters The requested database resource state. * @param options The options parameters. */ async beginCreateOrUpdate( resourceGroupName: string, serverName: string, databaseName: string, parameters: Database, options?: DatabasesCreateOrUpdateOptionalParams ): Promise< SimplePollerLike< OperationState, DatabasesCreateOrUpdateResponse > > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback } }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON() } }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, serverName, databaseName, parameters, options }, spec: createOrUpdateOperationSpec }); const poller = await createHttpPoller< DatabasesCreateOrUpdateResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "azure-async-operation" }); await poller.poll(); return poller; } /** * Creates a new database or updates an existing database. * @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 parameters The requested database resource state. * @param options The options parameters. */ async beginCreateOrUpdateAndWait( resourceGroupName: string, serverName: string, databaseName: string, parameters: Database, options?: DatabasesCreateOrUpdateOptionalParams ): Promise { const poller = await this.beginCreateOrUpdate( resourceGroupName, serverName, databaseName, parameters, options ); return poller.pollUntilDone(); } /** * Deletes the database. * @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. */ async beginDelete( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesDeleteOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback } }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON() } }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, serverName, databaseName, options }, spec: deleteOperationSpec }); const poller = await createHttpPoller>(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "location" }); await poller.poll(); return poller; } /** * Deletes the database. * @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. */ async beginDeleteAndWait( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesDeleteOptionalParams ): Promise { const poller = await this.beginDelete( resourceGroupName, serverName, databaseName, options ); return poller.pollUntilDone(); } /** * Updates an existing database. * @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 parameters The requested database resource state. * @param options The options parameters. */ async beginUpdate( resourceGroupName: string, serverName: string, databaseName: string, parameters: DatabaseUpdate, options?: DatabasesUpdateOptionalParams ): Promise< SimplePollerLike< OperationState, DatabasesUpdateResponse > > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback } }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON() } }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, serverName, databaseName, parameters, options }, spec: updateOperationSpec }); const poller = await createHttpPoller< DatabasesUpdateResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "location" }); await poller.poll(); return poller; } /** * Updates an existing database. * @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 parameters The requested database resource state. * @param options The options parameters. */ async beginUpdateAndWait( resourceGroupName: string, serverName: string, databaseName: string, parameters: DatabaseUpdate, options?: DatabasesUpdateOptionalParams ): Promise { const poller = await this.beginUpdate( resourceGroupName, serverName, databaseName, parameters, options ); return poller.pollUntilDone(); } /** * Exports a database. * @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 parameters The database export request parameters. * @param options The options parameters. */ async beginExport( resourceGroupName: string, serverName: string, databaseName: string, parameters: ExportDatabaseDefinition, options?: DatabasesExportOptionalParams ): Promise< SimplePollerLike< OperationState, DatabasesExportResponse > > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback } }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON() } }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, serverName, databaseName, parameters, options }, spec: exportOperationSpec }); const poller = await createHttpPoller< DatabasesExportResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Exports a database. * @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 parameters The database export request parameters. * @param options The options parameters. */ async beginExportAndWait( resourceGroupName: string, serverName: string, databaseName: string, parameters: ExportDatabaseDefinition, options?: DatabasesExportOptionalParams ): Promise { const poller = await this.beginExport( resourceGroupName, serverName, databaseName, parameters, options ); return poller.pollUntilDone(); } /** * Failovers a database. * @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 to failover. * @param options The options parameters. */ async beginFailover( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesFailoverOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback } }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON() } }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, serverName, databaseName, options }, spec: failoverOperationSpec }); const poller = await createHttpPoller>(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Failovers a database. * @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 to failover. * @param options The options parameters. */ async beginFailoverAndWait( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesFailoverOptionalParams ): Promise { const poller = await this.beginFailover( resourceGroupName, serverName, databaseName, options ); return poller.pollUntilDone(); } /** * Imports a bacpac into a new database. * @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 parameters The database import request parameters. * @param options The options parameters. */ async beginImport( resourceGroupName: string, serverName: string, databaseName: string, parameters: ImportExistingDatabaseDefinition, options?: DatabasesImportOptionalParams ): Promise< SimplePollerLike< OperationState, DatabasesImportResponse > > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback } }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON() } }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, serverName, databaseName, parameters, options }, spec: importOperationSpec }); const poller = await createHttpPoller< DatabasesImportResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Imports a bacpac into a new database. * @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 parameters The database import request parameters. * @param options The options parameters. */ async beginImportAndWait( resourceGroupName: string, serverName: string, databaseName: string, parameters: ImportExistingDatabaseDefinition, options?: DatabasesImportOptionalParams ): Promise { const poller = await this.beginImport( resourceGroupName, serverName, databaseName, parameters, options ); return poller.pollUntilDone(); } /** * Renames a database. * @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 to rename. * @param parameters The resource move definition for renaming this database. * @param options The options parameters. */ rename( resourceGroupName: string, serverName: string, databaseName: string, parameters: ResourceMoveDefinition, options?: DatabasesRenameOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, parameters, options }, renameOperationSpec ); } /** * Pauses a database. * @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 to be paused. * @param options The options parameters. */ async beginPause( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesPauseOptionalParams ): Promise< SimplePollerLike< OperationState, DatabasesPauseResponse > > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback } }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON() } }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, serverName, databaseName, options }, spec: pauseOperationSpec }); const poller = await createHttpPoller< DatabasesPauseResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Pauses a database. * @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 to be paused. * @param options The options parameters. */ async beginPauseAndWait( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesPauseOptionalParams ): Promise { const poller = await this.beginPause( resourceGroupName, serverName, databaseName, options ); return poller.pollUntilDone(); } /** * Resumes a database. * @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 to be resumed. * @param options The options parameters. */ async beginResume( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesResumeOptionalParams ): Promise< SimplePollerLike< OperationState, DatabasesResumeResponse > > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback } }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON() } }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, serverName, databaseName, options }, spec: resumeOperationSpec }); const poller = await createHttpPoller< DatabasesResumeResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Resumes a database. * @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 to be resumed. * @param options The options parameters. */ async beginResumeAndWait( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesResumeOptionalParams ): Promise { const poller = await this.beginResume( resourceGroupName, serverName, databaseName, options ); return poller.pollUntilDone(); } /** * Upgrades a data warehouse. * @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 to be upgraded. * @param options The options parameters. */ async beginUpgradeDataWarehouse( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesUpgradeDataWarehouseOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback } }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON() } }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, serverName, databaseName, options }, spec: upgradeDataWarehouseOperationSpec }); const poller = await createHttpPoller>(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Upgrades a data warehouse. * @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 to be upgraded. * @param options The options parameters. */ async beginUpgradeDataWarehouseAndWait( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabasesUpgradeDataWarehouseOptionalParams ): Promise { const poller = await this.beginUpgradeDataWarehouse( resourceGroupName, serverName, databaseName, options ); return poller.pollUntilDone(); } /** * Gets a list of databases in an elastic pool. * @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 elasticPoolName The name of the elastic pool. * @param options The options parameters. */ private _listByElasticPool( resourceGroupName: string, serverName: string, elasticPoolName: string, options?: DatabasesListByElasticPoolOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, elasticPoolName, options }, listByElasticPoolOperationSpec ); } /** * Gets a list of inaccessible databases in a logical server * @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 options The options parameters. */ private _listInaccessibleByServer( resourceGroupName: string, serverName: string, options?: DatabasesListInaccessibleByServerOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, options }, listInaccessibleByServerOperationSpec ); } /** * ListByServerNext * @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 nextLink The nextLink from the previous successful call to the ListByServer method. * @param options The options parameters. */ private _listByServerNext( resourceGroupName: string, serverName: string, nextLink: string, options?: DatabasesListByServerNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, nextLink, options }, listByServerNextOperationSpec ); } /** * ListByElasticPoolNext * @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 elasticPoolName The name of the elastic pool. * @param nextLink The nextLink from the previous successful call to the ListByElasticPool method. * @param options The options parameters. */ private _listByElasticPoolNext( resourceGroupName: string, serverName: string, elasticPoolName: string, nextLink: string, options?: DatabasesListByElasticPoolNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, elasticPoolName, nextLink, options }, listByElasticPoolNextOperationSpec ); } /** * ListInaccessibleByServerNext * @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 nextLink The nextLink from the previous successful call to the ListInaccessibleByServer * method. * @param options The options parameters. */ private _listInaccessibleByServerNext( resourceGroupName: string, serverName: string, nextLink: string, options?: DatabasesListInaccessibleByServerNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, nextLink, options }, listInaccessibleByServerNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listMetricsOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metrics", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.MetricListResult } }, queryParameters: [Parameters.apiVersion, Parameters.filter], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.accept], serializer }; const listMetricDefinitionsOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metricDefinitions", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.MetricDefinitionListResult } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.accept], serializer }; const listByServerOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DatabaseListResult }, default: {} }, queryParameters: [Parameters.skipToken, Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.Database }, default: {} }, queryParameters: [ Parameters.apiVersion1, Parameters.expand, Parameters.filter1 ], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.accept], serializer }; const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.Database }, 201: { bodyMapper: Mappers.Database }, 202: { bodyMapper: Mappers.Database }, 204: { bodyMapper: Mappers.Database }, default: {} }, requestBody: Parameters.parameters3, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.contentType, Parameters.accept], mediaType: "json", serializer }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}", httpMethod: "DELETE", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: {} }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], serializer }; const updateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}", httpMethod: "PATCH", responses: { 200: { bodyMapper: Mappers.Database }, 201: { bodyMapper: Mappers.Database }, 202: { bodyMapper: Mappers.Database }, 204: { bodyMapper: Mappers.Database }, default: {} }, requestBody: Parameters.parameters4, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.contentType, Parameters.accept], mediaType: "json", serializer }; const exportOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/export", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.ImportExportOperationResult }, 201: { bodyMapper: Mappers.ImportExportOperationResult }, 202: { bodyMapper: Mappers.ImportExportOperationResult }, 204: { bodyMapper: Mappers.ImportExportOperationResult }, default: {} }, requestBody: Parameters.parameters5, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.contentType, Parameters.accept], mediaType: "json", serializer }; const failoverOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/failover", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: {} }, queryParameters: [Parameters.apiVersion1, Parameters.replicaType], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], serializer }; const importOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.ImportExportOperationResult }, 201: { bodyMapper: Mappers.ImportExportOperationResult }, 202: { bodyMapper: Mappers.ImportExportOperationResult }, 204: { bodyMapper: Mappers.ImportExportOperationResult }, default: {} }, requestBody: Parameters.parameters6, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.contentType, Parameters.accept], mediaType: "json", serializer }; const renameOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/move", httpMethod: "POST", responses: { 200: {}, default: {} }, requestBody: Parameters.parameters7, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.contentType], mediaType: "json", serializer }; const pauseOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.Database }, 201: { bodyMapper: Mappers.Database }, 202: { bodyMapper: Mappers.Database }, 204: { bodyMapper: Mappers.Database }, default: {} }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.accept], serializer }; const resumeOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.Database }, 201: { bodyMapper: Mappers.Database }, 202: { bodyMapper: Mappers.Database }, 204: { bodyMapper: Mappers.Database }, default: {} }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.accept], serializer }; const upgradeDataWarehouseOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: {} }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], serializer }; const listByElasticPoolOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/databases", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DatabaseListResult }, default: {} }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.elasticPoolName ], headerParameters: [Parameters.accept], serializer }; const listInaccessibleByServerOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/inaccessibleDatabases", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DatabaseListResult }, default: {} }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName ], headerParameters: [Parameters.accept], serializer }; const listByServerNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DatabaseListResult }, default: {} }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer }; const listByElasticPoolNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DatabaseListResult }, default: {} }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.elasticPoolName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer }; const listInaccessibleByServerNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DatabaseListResult }, default: {} }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer };