本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
删除数据库
您可以使用以下代码段来删除数据库。
- 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
-
以下代码段用 AWS SDK于 JavaScript v3。有关如何安装客户端和用法的更多信息,请参阅 Timestream Write Client-f AWS SDK or JavaScript v3。
另请参阅类 DeleteDatabaseCommand和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; } }
以下代码段使用 for JavaScript V2 样式。 AWS SDK它基于 Node.js 示例 Amazon Timestream 中的示例 LiveAnalytics 应用程序,供其
上使用。 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()); } }
更新数据库
列出数据库