Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.
Auflisten von Tabellen
Sie können die folgenden Codefragmente verwenden, um Tabellen aufzulisten.
Anmerkung
Diese Codefragmente basieren auf vollständigen Beispielanwendungen auf. GitHub
- Java
-
public void listTables() { System.out.println("Listing tables"); ListTablesRequest request = new ListTablesRequest(); request.setDatabaseName(DATABASE_NAME); ListTablesResult result = amazonTimestreamWrite.listTables(request); printTables(result.getTables()); String nextToken = result.getNextToken(); while (nextToken != null && !nextToken.isEmpty()) { request.setNextToken(nextToken); ListTablesResult nextResult = amazonTimestreamWrite.listTables(request); printTables(nextResult.getTables()); nextToken = nextResult.getNextToken(); } } private void printTables(List<Table> tables) { for (Table table : tables) { System.out.println(table.getTableName()); } }
- Java v2
-
public void listTables() { System.out.println("Listing tables"); ListTablesRequest request = ListTablesRequest.builder().databaseName(DATABASE_NAME).maxResults(2).build(); ListTablesIterable listTablesIterable = timestreamWriteClient.listTablesPaginator(request); for(ListTablesResponse listTablesResponse : listTablesIterable) { final List<Table> tables = listTablesResponse.tables(); tables.forEach(table -> System.out.println(table.tableName())); } }
- Go
-
listTablesMaxResult := int64(15) listTablesInput := ×treamwrite.ListTablesInput{ DatabaseName: aws.String(*databaseName), MaxResults: &listTablesMaxResult, } listTablesOutput, err := writeSvc.ListTables(listTablesInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("List tables is successful, below is the output:") fmt.Println(listTablesOutput) }
- Python
-
def list_tables(self): print("Listing tables") try: result = self.client.list_tables(DatabaseName=Constant.DATABASE_NAME, MaxResults=5) self.__print_tables(result['Tables']) next_token = result.get('NextToken', None) while next_token: result = self.client.list_tables(DatabaseName=Constant.DATABASE_NAME, NextToken=next_token, MaxResults=5) self.__print_tables(result['Tables']) next_token = result.get('NextToken', None) except Exception as err: print("List tables failed:", err)
- Node.js
-
Der folgende Codeausschnitt wird AWS SDK für JavaScript Version 3 verwendet. Weitere Informationen zur Installation und Verwendung des Clients finden Sie unter Timestream Write Client — AWS SDK for v3. JavaScript
Siehe auch Klasse ListTablesCommand und ListTables.
import { TimestreamWriteClient, ListTablesCommand } from "@aws-sdk/client-timestream-write"; const writeClient = new TimestreamWriteClient({ region: "us-east-1" }); const params = { DatabaseName: "testDbFromNode", MaxResults: 15 }; const command = new ListTablesCommand(params); getTablesList(null); async function getTablesList(nextToken) { if (nextToken) { params.NextToken = nextToken; } try { const data = await writeClient.send(command); data.Tables.forEach(function (table) { console.log(table.TableName); }); if (data.NextToken) { return getTablesList(data.NextToken); } } catch (error) { console.log("Error while listing tables", error); } }
Das folgende Snippet verwendet den AWS SDK for JavaScript V2-Stil. Es basiert auf der Beispielanwendung unter Node.js Beispiel Amazon Timestream für die LiveAnalytics Anwendung auf GitHub
. async function listTables() { console.log("Listing tables:"); const tables = await getTablesList(null); tables.forEach(function(table){ console.log(table.TableName); }); } function getTablesList(nextToken, tables = []) { var params = { DatabaseName: constants.DATABASE_NAME, MaxResults: 15 }; if(nextToken) { params.NextToken = nextToken; } return writeClient.listTables(params).promise() .then( (data) => { tables.push.apply(tables, data.Tables); if (data.NextToken) { return getTablesList(data.NextToken, tables); } else { return tables; } }, (err) => { console.log("Error while listing databases", err); }); }
- .NET
-
public async Task ListTables() { Console.WriteLine("Listing Tables"); try { var listTablesRequest = new ListTablesRequest { MaxResults = 5, DatabaseName = Constants.DATABASE_NAME }; ListTablesResponse response = await writeClient.ListTablesAsync(listTablesRequest); PrintTables(response.Tables); string nextToken = response.NextToken; while (nextToken != null) { listTablesRequest.NextToken = nextToken; response = await writeClient.ListTablesAsync(listTablesRequest); PrintTables(response.Tables); nextToken = response.NextToken; } } catch (Exception e) { Console.WriteLine("List table failed:" + e.ToString()); } } private void PrintTables(List<Table> tables) { foreach (Table table in tables) Console.WriteLine($"Table: {table.TableName}"); }