Hapus tabel - Amazon Timestream

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Hapus tabel

Anda dapat menggunakan cuplikan kode berikut untuk menghapus tabel.

catatan

Cuplikan kode ini didasarkan pada contoh aplikasi lengkap. GitHub Untuk informasi selengkapnya tentang cara memulai dengan contoh aplikasi, lihatAplikasi sampel.

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

Cuplikan berikut digunakan AWS SDK untuk JavaScript v3. Untuk informasi selengkapnya tentang cara menginstal klien dan penggunaan, lihat Timestream Write Client - AWS SDK untuk JavaScript v3.

Lihat juga kelas DeleteTableCommand dan 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; } }

Cuplikan berikut menggunakan gaya AWS SDK for JavaScript V2. Hal ini didasarkan pada contoh aplikasi di Node.js sampel Amazon Timestream untuk LiveAnalytics aplikasi pada. 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()); } }