Eliminar tabla - Amazon Timestream

Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.

Eliminar tabla

Puede utilizar los siguientes fragmentos de código para eliminar una tabla.

nota

Estos fragmentos de código se basan en aplicaciones de muestra completas en. GitHub Para obtener más información sobre cómo empezar a utilizar las aplicaciones de ejemplo, consulte. Aplicación de muestra

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

El siguiente fragmento se utiliza AWS SDK para JavaScript la versión 3. Para obtener más información sobre cómo instalar el cliente y su uso, consulte Timestream Write Client, para la versión 3. AWS SDK JavaScript

Consulte también Class y. DeleteTableCommand 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; } }

El siguiente fragmento usa el estilo AWS SDK for JavaScript V2. Se basa en la aplicación de ejemplo de Node.js, ejemplo de Amazon Timestream LiveAnalytics para su aplicación en. 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()); } }