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.
Lista de tablas
Puede usar los siguientes fragmentos de código para enumerar tablas.
nota
Estos fragmentos de código se basan en aplicaciones de muestra completas en. 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
-
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. ListTablesCommand 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); } }
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 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}"); }