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.
Enumeración de bases de datos
Puede usar los siguientes fragmentos de código para enumerar sus bases de datos.
nota
Estos fragmentos de código se basan en aplicaciones de muestra completas en. GitHub
- Java
-
public void listDatabases() { System.out.println("Listing databases"); ListDatabasesRequest request = new ListDatabasesRequest(); ListDatabasesResult result = amazonTimestreamWrite.listDatabases(request); final List<Database> databases = result.getDatabases(); printDatabases(databases); String nextToken = result.getNextToken(); while (nextToken != null && !nextToken.isEmpty()) { request.setNextToken(nextToken); ListDatabasesResult nextResult = amazonTimestreamWrite.listDatabases(request); final List<Database> nextDatabases = nextResult.getDatabases(); printDatabases(nextDatabases); nextToken = nextResult.getNextToken(); } } private void printDatabases(List<Database> databases) { for (Database db : databases) { System.out.println(db.getDatabaseName()); } }
- Java v2
-
public void listDatabases() { System.out.println("Listing databases"); ListDatabasesRequest request = ListDatabasesRequest.builder().maxResults(2).build(); ListDatabasesIterable listDatabasesIterable = timestreamWriteClient.listDatabasesPaginator(request); for(ListDatabasesResponse listDatabasesResponse : listDatabasesIterable) { final List<Database> databases = listDatabasesResponse.databases(); databases.forEach(database -> System.out.println(database.databaseName())); } }
- Go
-
// List databases. listDatabasesMaxResult := int64(15) listDatabasesInput := ×treamwrite.ListDatabasesInput{ MaxResults: &listDatabasesMaxResult, } listDatabasesOutput, err := writeSvc.ListDatabases(listDatabasesInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("List databases is successful, below is the output:") fmt.Println(listDatabasesOutput) }
- Python
-
def list_databases(self): print("Listing databases") try: result = self.client.list_databases(MaxResults=5) self._print_databases(result['Databases']) next_token = result.get('NextToken', None) while next_token: result = self.client.list_databases(NextToken=next_token, MaxResults=5) self._print_databases(result['Databases']) next_token = result.get('NextToken', None) except Exception as err: print("List databases 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. ListDatabasesCommand ListDatabases
import { TimestreamWriteClient, ListDatabasesCommand } from "@aws-sdk/client-timestream-write"; const writeClient = new TimestreamWriteClient({ region: "us-east-1" }); const params = { MaxResults: 15 }; const command = new ListDatabasesCommand(params); getDatabasesList(null); async function getDatabasesList(nextToken) { if (nextToken) { params.NextToken = nextToken; } try { const data = await writeClient.send(command); data.Databases.forEach(function (database) { console.log(database.DatabaseName); }); if (data.NextToken) { return getDatabasesList(data.NextToken); } } catch (error) { console.log("Error while listing databases", 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 listDatabases() { console.log("Listing databases:"); const databases = await getDatabasesList(null); databases.forEach(function(database){ console.log(database.DatabaseName); }); } function getDatabasesList(nextToken, databases = []) { var params = { MaxResults: 15 }; if(nextToken) { params.NextToken = nextToken; } return writeClient.listDatabases(params).promise() .then( (data) => { databases.push.apply(databases, data.Databases); if (data.NextToken) { return getDatabasesList(data.NextToken, databases); } else { return databases; } }, (err) => { console.log("Error while listing databases", err); }); }
- .NET
-
public async Task ListDatabases() { Console.WriteLine("Listing Databases"); try { var listDatabasesRequest = new ListDatabasesRequest { MaxResults = 5 }; ListDatabasesResponse response = await writeClient.ListDatabasesAsync(listDatabasesRequest); PrintDatabases(response.Databases); var nextToken = response.NextToken; while (nextToken != null) { listDatabasesRequest.NextToken = nextToken; response = await writeClient.ListDatabasesAsync(listDatabasesRequest); PrintDatabases(response.Databases); nextToken = response.NextToken; } } catch (Exception e) { Console.WriteLine("List database failed:" + e.ToString()); } }