Supprimer une table - Amazon Timestream

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 une table

Vous pouvez utiliser les extraits de code suivants pour supprimer une table.

Note

Ces extraits de code sont basés sur des exemples complets d'applications sur. GitHub Pour plus d'informations sur la façon de démarrer avec les exemples d'applications, consultezExemple d'application.

Java
public void deleteTable() { System.out.println("Deleting table"); final DeleteTableRequest deleteTableRequest = new DeleteTableRequest(); deleteTableRequest.setDatabaseName(DATABASE_NAME); deleteTableRequest.setTableName(TABLE_NAME); try { DeleteTableResult result = amazonTimestreamWrite.deleteTable(deleteTableRequest); System.out.println("Delete table status: " + result.getSdkHttpMetadata().getHttpStatusCode()); } catch (final ResourceNotFoundException e) { System.out.println("Table " + TABLE_NAME + " doesn't exist = " + e); throw e; } catch (final Exception e) { System.out.println("Could not delete table " + TABLE_NAME + " = " + e); throw e; } }
Java v2
public void deleteTable() { System.out.println("Deleting table"); final DeleteTableRequest deleteTableRequest = DeleteTableRequest.builder() .databaseName(DATABASE_NAME).tableName(TABLE_NAME).build(); try { DeleteTableResponse response = timestreamWriteClient.deleteTable(deleteTableRequest); System.out.println("Delete table status: " + response.sdkHttpResponse().statusCode()); } catch (final ResourceNotFoundException e) { System.out.println("Table " + TABLE_NAME + " doesn't exist = " + e); throw e; } catch (final Exception e) { System.out.println("Could not delete table " + TABLE_NAME + " = " + e); throw e; } }
Go
deleteTableInput := &timestreamwrite.DeleteTableInput{ DatabaseName: aws.String(*databaseName), TableName: aws.String(*tableName), } _, err = writeSvc.DeleteTable(deleteTableInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("Table deleted", *tableName) }
Python
def delete_table(self): print("Deleting Table") try: result = self.client.delete_table(DatabaseName=Constant.DATABASE_NAME, TableName=Constant.TABLE_NAME) print("Delete table status [%s]" % result['ResponseMetadata']['HTTPStatusCode']) except self.client.exceptions.ResourceNotFoundException: print("Table [%s] doesn't exist" % Constant.TABLE_NAME) except Exception as err: print("Delete table 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 DeleteTableCommand et DeleteTable.

import { TimestreamWriteClient, DeleteTableCommand } from "@aws-sdk/client-timestream-write"; const writeClient = new TimestreamWriteClient({ region: "us-east-1" }); const params = { DatabaseName: "testDbFromNode", TableName: "testTableFromNode" }; const command = new DeleteTableCommand(params); try { const data = await writeClient.send(command); console.log("Deleted table"); } catch (error) { if (error.code === 'ResourceNotFoundException') { console.log(`Table ${params.TableName} or Database ${params.DatabaseName} doesn't exist.`); } else { console.log("Delete table 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 deleteTable() { console.log("Deleting Table"); const params = { DatabaseName: constants.DATABASE_NAME, TableName: constants.TABLE_NAME }; const promise = writeClient.deleteTable(params).promise(); await promise.then( function (data) { console.log("Deleted table"); }, function(err) { if (err.code === 'ResourceNotFoundException') { console.log(`Table ${params.TableName} or Database ${params.DatabaseName} doesn't exists.`); } else { console.log("Delete table failed.", err); throw err; } } ); }
.NET
public async Task DeleteTable() { Console.WriteLine("Deleting table"); try { var deleteTableRequest = new DeleteTableRequest { DatabaseName = Constants.DATABASE_NAME, TableName = Constants.TABLE_NAME }; DeleteTableResponse response = await writeClient.DeleteTableAsync(deleteTableRequest); Console.WriteLine($"Table {Constants.TABLE_NAME} delete request status: {response.HttpStatusCode}"); } catch (ResourceNotFoundException) { Console.WriteLine($"Table {Constants.TABLE_NAME} does not exists"); } catch (Exception e) { Console.WriteLine("Exception while deleting table:" + e.ToString()); } }