本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
描述資料庫
您可以使用下列程式碼片段來取得新建立資料庫屬性的相關資訊。
- Java
-
public void describeDatabase() { System.out.println("Describing database"); final DescribeDatabaseRequest describeDatabaseRequest = new DescribeDatabaseRequest(); describeDatabaseRequest.setDatabaseName(DATABASE_NAME); try { DescribeDatabaseResult result = amazonTimestreamWrite.describeDatabase(describeDatabaseRequest); final Database databaseRecord = result.getDatabase(); final String databaseId = databaseRecord.getArn(); System.out.println("Database " + DATABASE_NAME + " has id " + databaseId); } catch (final Exception e) { System.out.println("Database doesn't exist = " + e); throw e; } }
- Java v2
-
public void describeDatabase() { System.out.println("Describing database"); final DescribeDatabaseRequest describeDatabaseRequest = DescribeDatabaseRequest.builder() .databaseName(DATABASE_NAME).build(); try { DescribeDatabaseResponse response = timestreamWriteClient.describeDatabase(describeDatabaseRequest); final Database databaseRecord = response.database(); final String databaseId = databaseRecord.arn(); System.out.println("Database " + DATABASE_NAME + " has id " + databaseId); } catch (final Exception e) { System.out.println("Database doesn't exist = " + e); throw e; } }
- Go
-
describeDatabaseOutput, err := writeSvc.DescribeDatabase(describeDatabaseInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("Describe database is successful, below is the output:") fmt.Println(describeDatabaseOutput) }
- Python
-
def describe_database(self): print("Describing database") try: result = self.client.describe_database(DatabaseName=Constant.DATABASE_NAME) print("Database [%s] has id [%s]" % (Constant.DATABASE_NAME, result['Database']['Arn'])) except self.client.exceptions.ResourceNotFoundException: print("Database doesn't exist") except Exception as err: print("Describe database failed:", err)
- Node.js
-
下列程式碼片段用於 AWS SDK JavaScript v3。如需如何安裝用戶端和用量的詳細資訊,請參閱 Timestream Write Client - AWS SDK for JavaScript v3。
另請參閱類別 DescribeDatabaseCommand 和 DescribeDatabase。
import { TimestreamWriteClient, DescribeDatabaseCommand } from "@aws-sdk/client-timestream-write"; const writeClient = new TimestreamWriteClient({ region: "us-east-1" }); const params = { DatabaseName: "testDbFromNode" }; const command = new DescribeDatabaseCommand(params); try { const data = await writeClient.send(command); console.log(`Database ${data.Database.DatabaseName} has id ${data.Database.Arn}`); } catch (error) { if (error.code === 'ResourceNotFoundException') { console.log("Database doesn't exist."); } else { console.log("Describe database failed.", error); throw error; } }
下列程式碼片段使用 AWS SDK JavaScript V2 樣式的 。它以 Node.js 範例應用程式為基礎,適用於 上的 LiveAnalytics 應用程式 GitHub
。 async function describeDatabase () { console.log("Describing Database"); const params = { DatabaseName: constants.DATABASE_NAME }; const promise = writeClient.describeDatabase(params).promise(); await promise.then( (data) => { console.log(`Database ${data.Database.DatabaseName} has id ${data.Database.Arn}`); }, (err) => { if (err.code === 'ResourceNotFoundException') { console.log("Database doesn't exist."); } else { console.log("Describe database failed.", err); throw err; } } ); }
- .NET
-
public async Task DescribeDatabase() { Console.WriteLine("Describing Database"); try { var describeDatabaseRequest = new DescribeDatabaseRequest { DatabaseName = Constants.DATABASE_NAME }; DescribeDatabaseResponse response = await writeClient.DescribeDatabaseAsync(describeDatabaseRequest); Console.WriteLine($"Database {Constants.DATABASE_NAME} has id:{response.Database.Arn}"); } catch (ResourceNotFoundException) { Console.WriteLine("Database does not exist."); } catch (Exception e) { Console.WriteLine("Describe database failed:" + e.ToString()); } }
建立資料庫
更新資料庫