As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.
Excluir banco de dados
Você pode usar o seguinte trecho de código para excluir um banco de dados.
nota
Esses trechos de código são baseados em exemplos completos de aplicativos em. GitHub
- Java
-
public void deleteDatabase() { System.out.println("Deleting database"); final DeleteDatabaseRequest deleteDatabaseRequest = new DeleteDatabaseRequest(); deleteDatabaseRequest.setDatabaseName(DATABASE_NAME); try { DeleteDatabaseResult result = amazonTimestreamWrite.deleteDatabase(deleteDatabaseRequest); System.out.println("Delete database status: " + result.getSdkHttpMetadata().getHttpStatusCode()); } catch (final ResourceNotFoundException e) { System.out.println("Database " + DATABASE_NAME + " doesn't exist = " + e); throw e; } catch (final Exception e) { System.out.println("Could not delete Database " + DATABASE_NAME + " = " + e); throw e; } }
- Java v2
-
public void deleteDatabase() { System.out.println("Deleting database"); final DeleteDatabaseRequest deleteDatabaseRequest = new DeleteDatabaseRequest(); deleteDatabaseRequest.setDatabaseName(DATABASE_NAME); try { DeleteDatabaseResult result = amazonTimestreamWrite.deleteDatabase(deleteDatabaseRequest); System.out.println("Delete database status: " + result.getSdkHttpMetadata().getHttpStatusCode()); } catch (final ResourceNotFoundException e) { System.out.println("Database " + DATABASE_NAME + " doesn't exist = " + e); throw e; } catch (final Exception e) { System.out.println("Could not delete Database " + DATABASE_NAME + " = " + e); throw e; } }
- Go
-
deleteDatabaseInput := ×treamwrite.DeleteDatabaseInput{ DatabaseName: aws.String(*databaseName), } _, err = writeSvc.DeleteDatabase(deleteDatabaseInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("Database deleted:", *databaseName) }
- Python
-
def delete_database(self): print("Deleting Database") try: result = self.client.delete_database(DatabaseName=Constant.DATABASE_NAME) print("Delete database status [%s]" % result['ResponseMetadata']['HTTPStatusCode']) except self.client.exceptions.ResourceNotFoundException: print("database [%s] doesn't exist" % Constant.DATABASE_NAME) except Exception as err: print("Delete database failed:", err)
- Node.js
-
O trecho a seguir é usado AWS SDK para JavaScript a v3. Para obter mais informações sobre como instalar o cliente e o uso, consulte Timestream Write Client - AWS SDK for JavaScript v3.
Veja também Classe DeleteDatabaseCommand DeleteDatabasee.
import { TimestreamWriteClient, DeleteDatabaseCommand } from "@aws-sdk/client-timestream-write"; const writeClient = new TimestreamWriteClient({ region: "us-east-1" }); const params = { DatabaseName: "testDbFromNode" }; const command = new DeleteDatabaseCommand(params); try { const data = await writeClient.send(command); console.log("Deleted database"); } catch (error) { if (error.code === 'ResourceNotFoundException') { console.log(`Database ${params.DatabaseName} doesn't exists.`); } else { console.log("Delete database failed.", error); throw error; } }
O trecho a seguir usa o estilo AWS SDK for JavaScript V2. Ele se baseia no aplicativo de exemplo em Node.js, exemplo do Amazon Timestream LiveAnalytics
para aplicação em. GitHub async function deleteDatabase() { console.log("Deleting Database"); const params = { DatabaseName: constants.DATABASE_NAME }; const promise = writeClient.deleteDatabase(params).promise(); await promise.then( function (data) { console.log("Deleted database"); }, function(err) { if (err.code === 'ResourceNotFoundException') { console.log(`Database ${params.DatabaseName} doesn't exists.`); } else { console.log("Delete database failed.", err); throw err; } } ); }
- .NET
-
public async Task DeleteDatabase() { Console.WriteLine("Deleting database"); try { var deleteDatabaseRequest = new DeleteDatabaseRequest { DatabaseName = Constants.DATABASE_NAME }; DeleteDatabaseResponse response = await writeClient.DeleteDatabaseAsync(deleteDatabaseRequest); Console.WriteLine($"Database {Constants.DATABASE_NAME} delete request status:{response.HttpStatusCode}"); } catch (ResourceNotFoundException) { Console.WriteLine($"Database {Constants.DATABASE_NAME} does not exists"); } catch (Exception e) { Console.WriteLine("Exception while deleting database:" + e.ToString()); } }