Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.
Datenbank löschen
Sie können den folgenden Codeausschnitt verwenden, um eine Datenbank zu löschen.
Anmerkung
Diese Codefragmente basieren auf vollständigen Beispielanwendungen auf. 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
-
Der folgende Codeausschnitt wird AWS SDK für JavaScript Version 3 verwendet. Weitere Informationen zur Installation und Verwendung des Clients finden Sie unter Timestream Write Client — AWS SDK for v3. JavaScript
Siehe auch Klasse DeleteDatabaseCommand und DeleteDatabase.
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; } }
Das folgende Snippet verwendet den AWS SDK for JavaScript V2-Stil. Es basiert auf der Beispielanwendung unter Node.js Beispiel Amazon Timestream für die LiveAnalytics Anwendung auf 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()); } }