기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
테이블 나열
다음 코드 조각을 사용하여 테이블을 나열할 수 있습니다.
- 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
-
다음 조각은 JavaScript v3에 를 사용합니다 AWS SDK. 클라이언트를 설치하는 방법과 사용량에 대한 자세한 내용은 JavaScript v3SDK용 Timestream Write Client - AWS를 참조하세요.
클래스 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); } }
다음 조각은 JavaScript V2 스타일에 를 AWS SDK 사용합니다. 이는 Node.js 샘플 Amazon Timestream LiveAnalytics 의 샘플 애플리케이션을 기반으로 합니다 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}"); }
테이블 삭제
데이터 쓰기