mirror of
https://github.com/hanzoai/azure-sdk-for-js.git
synced 2026-10-30 19:51:51 +00:00
Configurations: 'specification/sql/resource-manager/Microsoft.Sql/SQL/tspconfig.yaml', API Version: 2025-01-01, SDK Release Type: stable, and CommitSHA: '41784cfad64229e05cb37b1532a686a0cc3a60a9` in SpecRepo: 'https://github.com/Azure/azure-rest-api-specs' Pipeline run: https://dev.azure.com/azure-sdk/internal/_build/results?buildId=6276195 Refer to https://eng.ms/docs/products/azure-developer-experience/develop/sdk-release/sdk-release-prerequisites to prepare for SDK release. Release plan link: [https://azsdk-releaseplan-dashboard-hveph5aqhhcfhtgu](https://azsdk-releaseplan-dashboard-hveph5aqhhcfhtgu.westus-01.azurewebsites.net/?releasePlan=2227).[westus-01.azurewebsites.net/?releasePlan=2227](https://azsdk-releaseplan-dashboard-hveph5aqhhcfhtgu.westus-01.azurewebsites.net/?releasePlan=2227) Submitted by: [[email protected]](mailto:[email protected]) ### Release Plan Details Release Plan: https://azsdk-releaseplan-dashboard-hveph5aqhhcfhtgu.westus-01.azurewebsites.net/?releasePlan=2227 Spec pull request: [Azure/azure-rest-api-specs#41520](https://github.com/Azure/azure-rest-api-specs/pull/41520) Spec API version: --------- Co-authored-by: kazrael2119 <[email protected]>
232 lines
9.3 KiB
TypeScript
232 lines
9.3 KiB
TypeScript
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
import { SqlManagementClient } from "@azure/arm-sql";
|
|
import { DefaultAzureCredential } from "@azure/identity";
|
|
|
|
/**
|
|
* This sample demonstrates how to creates a new database or updates an existing database.
|
|
*
|
|
* @summary creates a new database or updates an existing database.
|
|
* x-ms-original-file: 2025-01-01/CreateManagedDatabaseLedger.json
|
|
*/
|
|
async function createsANewManagedDatabaseWithLedgerOn(): Promise<void> {
|
|
const credential = new DefaultAzureCredential();
|
|
const subscriptionId = "00000000-1111-2222-3333-444444444444";
|
|
const client = new SqlManagementClient(credential, subscriptionId);
|
|
const result = await client.managedDatabases.createOrUpdate(
|
|
"Default-SQL-SouthEastAsia",
|
|
"managedInstance",
|
|
"managedDatabase",
|
|
{ location: "southeastasia", isLedgerOn: true },
|
|
);
|
|
console.log(result);
|
|
}
|
|
|
|
/**
|
|
* This sample demonstrates how to creates a new database or updates an existing database.
|
|
*
|
|
* @summary creates a new database or updates an existing database.
|
|
* x-ms-original-file: 2025-01-01/ManagedDatabaseCreateCrossSubscriptionPointInTimeRestore.json
|
|
*/
|
|
async function createsANewManagedDatabaseUsingCrossSubscriptionPointInTimeRestore(): Promise<void> {
|
|
const credential = new DefaultAzureCredential();
|
|
const subscriptionId = "00000000-1111-2222-3333-444444444444";
|
|
const client = new SqlManagementClient(credential, subscriptionId);
|
|
const result = await client.managedDatabases.createOrUpdate(
|
|
"Default-SQL-SouthEastAsia",
|
|
"managedInstance",
|
|
"managedDatabase",
|
|
{
|
|
location: "southeastasia",
|
|
createMode: "PointInTimeRestore",
|
|
crossSubscriptionSourceDatabaseId:
|
|
"/subscriptions/11111111-2222-3333-4444-555555555555/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr2/databases/testdb",
|
|
crossSubscriptionTargetManagedInstanceId:
|
|
"/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr",
|
|
restorePointInTime: new Date("2017-07-14T05:35:31.503Z"),
|
|
},
|
|
);
|
|
console.log(result);
|
|
}
|
|
|
|
/**
|
|
* This sample demonstrates how to creates a new database or updates an existing database.
|
|
*
|
|
* @summary creates a new database or updates an existing database.
|
|
* x-ms-original-file: 2025-01-01/ManagedDatabaseCreateMax.json
|
|
*/
|
|
async function createsANewManagedDatabaseWithMaximalProperties(): Promise<void> {
|
|
const credential = new DefaultAzureCredential();
|
|
const subscriptionId = "00000000-1111-2222-3333-444444444444";
|
|
const client = new SqlManagementClient(credential, subscriptionId);
|
|
const result = await client.managedDatabases.createOrUpdate(
|
|
"Default-SQL-SouthEastAsia",
|
|
"managedInstance",
|
|
"managedDatabase",
|
|
{ location: "southeastasia", tags: { tagKey1: "TagValue1" } },
|
|
);
|
|
console.log(result);
|
|
}
|
|
|
|
/**
|
|
* This sample demonstrates how to creates a new database or updates an existing database.
|
|
*
|
|
* @summary creates a new database or updates an existing database.
|
|
* x-ms-original-file: 2025-01-01/ManagedDatabaseCreateMin.json
|
|
*/
|
|
async function createsANewManagedDatabaseWithMinimalProperties(): Promise<void> {
|
|
const credential = new DefaultAzureCredential();
|
|
const subscriptionId = "00000000-1111-2222-3333-444444444444";
|
|
const client = new SqlManagementClient(credential, subscriptionId);
|
|
const result = await client.managedDatabases.createOrUpdate(
|
|
"Default-SQL-SouthEastAsia",
|
|
"managedInstance",
|
|
"managedDatabase",
|
|
{ location: "southeastasia" },
|
|
);
|
|
console.log(result);
|
|
}
|
|
|
|
/**
|
|
* This sample demonstrates how to creates a new database or updates an existing database.
|
|
*
|
|
* @summary creates a new database or updates an existing database.
|
|
* x-ms-original-file: 2025-01-01/ManagedDatabaseCreatePointInTimeRestore.json
|
|
*/
|
|
async function createsANewManagedDatabaseUsingPointInTimeRestore(): Promise<void> {
|
|
const credential = new DefaultAzureCredential();
|
|
const subscriptionId = "00000000-1111-2222-3333-444444444444";
|
|
const client = new SqlManagementClient(credential, subscriptionId);
|
|
const result = await client.managedDatabases.createOrUpdate(
|
|
"Default-SQL-SouthEastAsia",
|
|
"managedInstance",
|
|
"managedDatabase",
|
|
{
|
|
location: "southeastasia",
|
|
createMode: "PointInTimeRestore",
|
|
restorePointInTime: new Date("2017-07-14T05:35:31.503Z"),
|
|
sourceDatabaseId:
|
|
"/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb",
|
|
},
|
|
);
|
|
console.log(result);
|
|
}
|
|
|
|
/**
|
|
* This sample demonstrates how to creates a new database or updates an existing database.
|
|
*
|
|
* @summary creates a new database or updates an existing database.
|
|
* x-ms-original-file: 2025-01-01/ManagedDatabaseCreateRecovery.json
|
|
*/
|
|
async function createsANewManagedDatabaseFromRestoringAGeoReplicatedBackup(): Promise<void> {
|
|
const credential = new DefaultAzureCredential();
|
|
const subscriptionId = "00000000-1111-2222-3333-444444444444";
|
|
const client = new SqlManagementClient(credential, subscriptionId);
|
|
const result = await client.managedDatabases.createOrUpdate(
|
|
"Default-SQL-SouthEastAsia",
|
|
"server1",
|
|
"testdb_recovered",
|
|
{
|
|
location: "southeastasia",
|
|
createMode: "Recovery",
|
|
recoverableDatabaseId:
|
|
"/subscriptions/11111111-2222-3333-4444-555555555555/resourceGroups/Default-SQL-WestEurope/providers/Microsoft.Sql/managedInstances/testsvr/recoverableDatabases/testdb",
|
|
},
|
|
);
|
|
console.log(result);
|
|
}
|
|
|
|
/**
|
|
* This sample demonstrates how to creates a new database or updates an existing database.
|
|
*
|
|
* @summary creates a new database or updates an existing database.
|
|
* x-ms-original-file: 2025-01-01/ManagedDatabaseCreateRestoreExternalBackup.json
|
|
*/
|
|
async function createsANewManagedDatabaseByRestoringFromAnExternalBackup(): Promise<void> {
|
|
const credential = new DefaultAzureCredential();
|
|
const subscriptionId = "00000000-1111-2222-3333-444444444444";
|
|
const client = new SqlManagementClient(credential, subscriptionId);
|
|
const result = await client.managedDatabases.createOrUpdate(
|
|
"Default-SQL-SouthEastAsia",
|
|
"managedInstance",
|
|
"managedDatabase",
|
|
{
|
|
location: "southeastasia",
|
|
autoCompleteRestore: true,
|
|
collation: "SQL_Latin1_General_CP1_CI_AS",
|
|
createMode: "RestoreExternalBackup",
|
|
lastBackupName: "last_backup_name",
|
|
storageContainerSasToken: "sv=2015-12-11&sr=c&sp=rl&sig=1234",
|
|
storageContainerUri: "https://myaccountname.blob.core.windows.net/backups",
|
|
},
|
|
);
|
|
console.log(result);
|
|
}
|
|
|
|
/**
|
|
* This sample demonstrates how to creates a new database or updates an existing database.
|
|
*
|
|
* @summary creates a new database or updates an existing database.
|
|
* x-ms-original-file: 2025-01-01/ManagedDatabaseCreateRestoreExternalBackupManagedIdentity.json
|
|
*/
|
|
async function createsANewManagedDatabaseByRestoringFromAnExternalBackupUsingManagedIdentity(): Promise<void> {
|
|
const credential = new DefaultAzureCredential();
|
|
const subscriptionId = "00000000-1111-2222-3333-444444444444";
|
|
const client = new SqlManagementClient(credential, subscriptionId);
|
|
const result = await client.managedDatabases.createOrUpdate(
|
|
"Default-SQL-SouthEastAsia",
|
|
"managedInstance",
|
|
"managedDatabase",
|
|
{
|
|
location: "southeastasia",
|
|
autoCompleteRestore: true,
|
|
collation: "SQL_Latin1_General_CP1_CI_AS",
|
|
createMode: "RestoreExternalBackup",
|
|
lastBackupName: "last_backup_name",
|
|
storageContainerIdentity: "ManagedIdentity",
|
|
storageContainerUri: "https://myaccountname.blob.core.windows.net/backups",
|
|
},
|
|
);
|
|
console.log(result);
|
|
}
|
|
|
|
/**
|
|
* This sample demonstrates how to creates a new database or updates an existing database.
|
|
*
|
|
* @summary creates a new database or updates an existing database.
|
|
* x-ms-original-file: 2025-01-01/ManagedDatabaseCreateRestoreLtrBackup.json
|
|
*/
|
|
async function createsANewManagedDatabaseFromRestoringALongTermRetentionBackup(): Promise<void> {
|
|
const credential = new DefaultAzureCredential();
|
|
const subscriptionId = "00000000-1111-2222-3333-444444444444";
|
|
const client = new SqlManagementClient(credential, subscriptionId);
|
|
const result = await client.managedDatabases.createOrUpdate(
|
|
"Default-SQL-SouthEastAsia",
|
|
"managedInstance",
|
|
"managedDatabase",
|
|
{
|
|
location: "southeastasia",
|
|
collation: "SQL_Latin1_General_CP1_CI_AS",
|
|
createMode: "RestoreExternalBackup",
|
|
storageContainerSasToken: "sv=2015-12-11&sr=c&sp=rl&sig=1234",
|
|
storageContainerUri: "https://myaccountname.blob.core.windows.net/backups",
|
|
},
|
|
);
|
|
console.log(result);
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
await createsANewManagedDatabaseWithLedgerOn();
|
|
await createsANewManagedDatabaseUsingCrossSubscriptionPointInTimeRestore();
|
|
await createsANewManagedDatabaseWithMaximalProperties();
|
|
await createsANewManagedDatabaseWithMinimalProperties();
|
|
await createsANewManagedDatabaseUsingPointInTimeRestore();
|
|
await createsANewManagedDatabaseFromRestoringAGeoReplicatedBackup();
|
|
await createsANewManagedDatabaseByRestoringFromAnExternalBackup();
|
|
await createsANewManagedDatabaseByRestoringFromAnExternalBackupUsingManagedIdentity();
|
|
await createsANewManagedDatabaseFromRestoringALongTermRetentionBackup();
|
|
}
|
|
|
|
main().catch(console.error);
|