Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
Supprimer la base de données
Vous pouvez utiliser l'extrait de code suivant pour supprimer une base de données.
Note
Ces extraits de code sont basés sur des exemples complets d'applications sur. 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
-
L'extrait de code suivant est utilisé AWS SDK pour JavaScript la version 3. Pour plus d'informations sur l'installation du client et son utilisation, consultez Timestream Write Client - AWS SDK for JavaScript v3.
Voir également Classe DeleteDatabaseCommand et 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; } }
L'extrait suivant utilise le style AWS SDK for JavaScript V2. Il est basé sur l'exemple d'application disponible sur Node.js, un exemple d'Amazon Timestream LiveAnalytics
pour une application sur. 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()); } }