Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Descrivi database
È possibile utilizzare i seguenti frammenti di codice per ottenere informazioni sugli attributi del database appena creato.
Nota
Questi frammenti di codice si basano su applicazioni di esempio complete su. GitHub
- 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
-
Il seguente frammento viene utilizzato AWS SDK per JavaScript la v3. Per ulteriori informazioni su come installare il client e sull'utilizzo, consulta Timestream Write Client - for v3. AWS SDK JavaScript
Vedi anche Class and. 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; } }
Il seguente frammento utilizza lo stile AWS SDK for JavaScript V2. Si basa sull'applicazione di esempio disponibile in Node.js, esempio Amazon Timestream LiveAnalytics
per l'applicazione su. 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()); } }