다음을 통해 공유


TableClient class

TableClient는 단일 테이블에서 작업을 수행할 수 있는 Azure Tables 서비스에 대한 클라이언트를 나타냅니다.

생성자

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

TableClient 클래스의 새 인스턴스를 만듭니다.

TableClient(string, string, SASCredential, TableServiceClientOptions)

TableClient 클래스의 새 인스턴스를 만듭니다.

TableClient(string, string, TableServiceClientOptions)

TableClient의 인스턴스를 만듭니다.

TableClient(string, string, TokenCredential, TableServiceClientOptions)

TableClient 클래스의 새 인스턴스를 만듭니다.

속성

pipeline

URL에 대한 HTTP 요청을 만들기 위한 파이프라인을 나타냅니다. 파이프라인에는 서버에 대한 요청 전후에 각 요청 조작을 관리하는 여러 정책이 있을 수 있습니다.

tableName

작업을 수행할 테이블의 이름입니다.

url

테이블 계정 URL

메서드

createEntity<T>(TableEntity<T>, OperationOptions)

테이블에 엔터티를 삽입합니다.

createTable(OperationOptions)

tableName이 클라이언트 생성자에 전달된 테이블을 만듭니다.

deleteEntity(string, string, DeleteTableEntityOptions)

테이블에서 지정된 엔터티를 삭제합니다.

deleteTable(OperationOptions)

모든 엔터티를 사용하여 현재 테이블을 영구적으로 삭제합니다.

fromConnectionString(string, string, TableServiceClientOptions)

연결 문자열에서 TableClient의 인스턴스를 만듭니다.

getAccessPolicy(OperationOptions)

공유 액세스 서명과 함께 사용할 수 있는 테이블에 지정된 저장된 액세스 정책에 대한 세부 정보를 검색합니다.

getEntity<T>(string, string, GetTableEntityOptions)

테이블의 단일 엔터티를 반환합니다.

listEntities<T>(ListTableEntitiesOptions)

테이블의 엔터티를 쿼리합니다.

setAccessPolicy(SignedIdentifier[], OperationOptions)

공유 액세스 서명과 함께 사용할 수 있는 테이블에 대해 저장된 액세스 정책을 설정합니다.

submitTransaction(TransactionAction[], OperationOptions)

작업 집합으로 구성된 트랜잭션을 제출합니다. 작업을 목록으로 제공하거나 TableTransaction 사용하여 트랜잭션을 빌드할 수 있습니다.

사용 예:

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient, TransactionAction } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const actions: TransactionAction[] = [
  ["create", { partitionKey: "p1", rowKey: "1", data: "test1" }],
  ["delete", { partitionKey: "p1", rowKey: "2" }],
  ["update", { partitionKey: "p1", rowKey: "3", data: "newTest" }, "Merge"],
];
const result = await client.submitTransaction(actions);

TableTransaction을 사용하는 예제 사용:

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient, TableTransaction } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const transaction = new TableTransaction();

// Call the available action in the TableTransaction object
transaction.createEntity({ partitionKey: "p1", rowKey: "1", data: "test1" });
transaction.deleteEntity("p1", "2");
transaction.updateEntity({ partitionKey: "p1", rowKey: "3", data: "newTest" }, "Merge");

// submitTransaction with the actions list on the transaction.
const result = await client.submitTransaction(transaction.actions);
updateEntity<T>(TableEntity<T>, UpdateMode, UpdateTableEntityOptions)

테이블의 엔터티를 업데이트합니다.

upsertEntity<T>(TableEntity<T>, UpdateMode, OperationOptions)

테이블의 엔터티를 Upsert합니다.

생성자 세부 정보

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

TableClient 클래스의 새 인스턴스를 만듭니다.

new TableClient(url: string, tableName: string, credential: NamedKeyCredential, options?: TableServiceClientOptions)

매개 변수

url

string

원하는 작업의 대상인 서비스 계정의 URL(예: "https://myaccount.table.core.windows.net")입니다.

tableName

string

테이블의 이름

credential
NamedKeyCredential

요청을 인증하는 데 사용되는 NamedKeyCredential입니다. 노드에 대해서만 지원됨

options
TableServiceClientOptions

선택적. HTTP 파이프라인을 구성하는 옵션입니다.

계정 이름/키를 사용하는 예제:

import { AzureNamedKeyCredential, TableClient } from "@azure/data-tables";

// Enter your storage account name and shared key
const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

// Use AzureNamedKeyCredential with storage account and account key
// AzureNamedKeyCredential is only available in Node.js runtime, not in browsers
const credential = new AzureNamedKeyCredential(account, accountKey);
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

TableClient(string, string, SASCredential, TableServiceClientOptions)

TableClient 클래스의 새 인스턴스를 만듭니다.

new TableClient(url: string, tableName: string, credential: SASCredential, options?: TableServiceClientOptions)

매개 변수

url

string

원하는 작업의 대상인 서비스 계정의 URL(예: "https://myaccount.table.core.windows.net")입니다.

tableName

string

테이블의 이름

credential
SASCredential

요청을 인증하는 데 사용되는 SASCredential

options
TableServiceClientOptions

선택적. HTTP 파이프라인을 구성하는 옵션입니다.

SAS 토큰을 사용하는 예제:

import { TableClient, AzureSASCredential } from "@azure/data-tables";

const account = "<account name>";
const sas = "<service Shared Access Signature Token>";
const tableName = "<tableName>";

const clientWithSAS = new TableClient(
  `https://${account}.table.core.windows.net`,
  tableName,
  new AzureSASCredential(sas),
);

TableClient(string, string, TableServiceClientOptions)

TableClient의 인스턴스를 만듭니다.

new TableClient(url: string, tableName: string, options?: TableServiceClientOptions)

매개 변수

url

string

Azure Storage 테이블 서비스를 가리키는 클라이언트 문자열(예: "https://myaccount.table.core.windows.net") "https://myaccount.table.core.windows.net?sasString"와 같은 SAS를 추가할 수 있습니다.

tableName

string

테이블의 이름

options
TableServiceClientOptions

HTTP 파이프라인을 구성하는 옵션입니다.

SAS 토큰을 추가하는 예제:

import { TableClient } from "@azure/data-tables";

const account = "<account name>";
const sasToken = "<SAS token>";
const tableName = "<tableName>";

const clientWithSAS = new TableClient(
  `https://${account}.table.core.windows.net?${sasToken}`,
  tableName,
);

TableClient(string, string, TokenCredential, TableServiceClientOptions)

TableClient 클래스의 새 인스턴스를 만듭니다.

new TableClient(url: string, tableName: string, credential: TokenCredential, options?: TableServiceClientOptions)

매개 변수

url

string

원하는 작업의 대상인 서비스 계정의 URL(예: "https://myaccount.table.core.windows.net")입니다.

tableName

string

테이블의 이름

credential
TokenCredential

요청을 인증하는 데 사용되는 Azure Active Directory 자격 증명

options
TableServiceClientOptions

선택적. HTTP 파이프라인을 구성하는 옵션입니다.

Azure Active Directory 자격 증명을 사용하는 예제:

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const credential = new DefaultAzureCredential();
const account = "<account name>";
const tableName = "<tableName>";

const clientWithAAD = new TableClient(
  `https://${account}.table.core.windows.net`,
  tableName,
  credential,
);

속성 세부 정보

pipeline

URL에 대한 HTTP 요청을 만들기 위한 파이프라인을 나타냅니다. 파이프라인에는 서버에 대한 요청 전후에 각 요청 조작을 관리하는 여러 정책이 있을 수 있습니다.

pipeline: Pipeline

속성 값

tableName

작업을 수행할 테이블의 이름입니다.

tableName: string

속성 값

string

url

테이블 계정 URL

url: string

속성 값

string

메서드 세부 정보

createEntity<T>(TableEntity<T>, OperationOptions)

테이블에 엔터티를 삽입합니다.

function createEntity<T>(entity: TableEntity<T>, options?: OperationOptions): Promise<TableInsertEntityHeaders>

매개 변수

entity

TableEntity<T>

테이블 엔터티의 속성입니다.

options
OperationOptions

옵션 매개 변수입니다.

엔터티 만들기 예제

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const testEntity = {
  partitionKey: "P1",
  rowKey: "R1",
  foo: "foo",
  bar: 123,
};
await client.createEntity(testEntity);

반환

createTable(OperationOptions)

tableName이 클라이언트 생성자에 전달된 테이블을 만듭니다.

function createTable(options?: OperationOptions): Promise<void>

매개 변수

options
OperationOptions

옵션 매개 변수입니다.

테이블 만들기 예제

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

// If the table 'newTable' already exists, createTable doesn't throw
await client.createTable();

반환

Promise<void>

deleteEntity(string, string, DeleteTableEntityOptions)

테이블에서 지정된 엔터티를 삭제합니다.

function deleteEntity(partitionKey: string, rowKey: string, options?: DeleteTableEntityOptions): Promise<TableDeleteEntityHeaders>

매개 변수

partitionKey

string

엔터티의 파티션 키입니다.

rowKey

string

엔터티의 행 키입니다.

options
DeleteTableEntityOptions

옵션 매개 변수입니다.

엔터티 삭제 예제

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

// deleteEntity deletes the entity that matches exactly the partitionKey and rowKey
await client.deleteEntity("<partitionKey>", "<rowKey>");

반환

deleteTable(OperationOptions)

모든 엔터티를 사용하여 현재 테이블을 영구적으로 삭제합니다.

function deleteTable(options?: OperationOptions): Promise<void>

매개 변수

options
OperationOptions

옵션 매개 변수입니다.

테이블 삭제 예제

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

await client.deleteTable();

반환

Promise<void>

fromConnectionString(string, string, TableServiceClientOptions)

연결 문자열에서 TableClient의 인스턴스를 만듭니다.

static function fromConnectionString(connectionString: string, tableName: string, options?: TableServiceClientOptions): TableClient

매개 변수

connectionString

string

Azure Storage 계정의 계정 연결 문자열 또는 SAS 연결 문자열입니다. [ 참고 - 계정 연결 문자열은 NODE.JS 런타임에서만 사용할 수 있습니다. ] 계정 연결 문자열 예제 - DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net SAS 연결 문자열 예제 - BlobEndpoint=https://myaccount.table.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString

tableName

string

options
TableServiceClientOptions

HTTP 파이프라인을 구성하는 옵션입니다.

반환

지정된 연결 문자열의 새 TableClient입니다.

getAccessPolicy(OperationOptions)

공유 액세스 서명과 함께 사용할 수 있는 테이블에 지정된 저장된 액세스 정책에 대한 세부 정보를 검색합니다.

function getAccessPolicy(options?: OperationOptions): Promise<GetAccessPolicyResponse>

매개 변수

options
OperationOptions

옵션 매개 변수입니다.

반환

getEntity<T>(string, string, GetTableEntityOptions)

테이블의 단일 엔터티를 반환합니다.

function getEntity<T>(partitionKey: string, rowKey: string, options?: GetTableEntityOptions): Promise<GetTableEntityResponse<TableEntityResult<T>>>

매개 변수

partitionKey

string

엔터티의 파티션 키입니다.

rowKey

string

엔터티의 행 키입니다.

options
GetTableEntityOptions

옵션 매개 변수입니다.

엔터티 가져오기 예제

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const entity = await client.getEntity("<partitionKey>", "<rowKey>");
console.log(`Entity: PartitionKey: ${entity.partitionKey} RowKey: ${entity.rowKey}`);

반환

listEntities<T>(ListTableEntitiesOptions)

테이블의 엔터티를 쿼리합니다.

function listEntities<T>(options?: ListTableEntitiesOptions): PagedAsyncIterableIterator<TableEntityResult<T>, TableEntityResultPage<T>, PageSettings>

매개 변수

options
ListTableEntitiesOptions

옵션 매개 변수입니다.

엔터티 나열 예제

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

let i = 0;
const entities = client.listEntities();
for await (const entity of entities) {
  console.log(`Entity${++i}: PartitionKey: ${entity.partitionKey} RowKey: ${entity.rowKey}`);
}

반환

setAccessPolicy(SignedIdentifier[], OperationOptions)

공유 액세스 서명과 함께 사용할 수 있는 테이블에 대해 저장된 액세스 정책을 설정합니다.

function setAccessPolicy(tableAcl: SignedIdentifier[], options?: OperationOptions): Promise<TableSetAccessPolicyHeaders>

매개 변수

tableAcl

SignedIdentifier[]

테이블의 액세스 제어 목록입니다.

options
OperationOptions

옵션 매개 변수입니다.

반환

submitTransaction(TransactionAction[], OperationOptions)

작업 집합으로 구성된 트랜잭션을 제출합니다. 작업을 목록으로 제공하거나 TableTransaction 사용하여 트랜잭션을 빌드할 수 있습니다.

사용 예:

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient, TransactionAction } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const actions: TransactionAction[] = [
  ["create", { partitionKey: "p1", rowKey: "1", data: "test1" }],
  ["delete", { partitionKey: "p1", rowKey: "2" }],
  ["update", { partitionKey: "p1", rowKey: "3", data: "newTest" }, "Merge"],
];
const result = await client.submitTransaction(actions);

TableTransaction을 사용하는 예제 사용:

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient, TableTransaction } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const transaction = new TableTransaction();

// Call the available action in the TableTransaction object
transaction.createEntity({ partitionKey: "p1", rowKey: "1", data: "test1" });
transaction.deleteEntity("p1", "2");
transaction.updateEntity({ partitionKey: "p1", rowKey: "3", data: "newTest" }, "Merge");

// submitTransaction with the actions list on the transaction.
const result = await client.submitTransaction(transaction.actions);
function submitTransaction(actions: TransactionAction[], options?: OperationOptions): Promise<TableTransactionResponse>

매개 변수

actions

TransactionAction[]

수행할 작업과 작업을 수행할 엔터티가 포함된 튜플

options
OperationOptions

요청에 대한 옵션입니다.

반환

updateEntity<T>(TableEntity<T>, UpdateMode, UpdateTableEntityOptions)

테이블의 엔터티를 업데이트합니다.

function updateEntity<T>(entity: TableEntity<T>, mode?: UpdateMode, options?: UpdateTableEntityOptions): Promise<TableUpdateEntityHeaders>

매개 변수

entity

TableEntity<T>

업데이트할 엔터티의 속성입니다.

mode
UpdateMode

엔터티를 업데이트하는 다양한 모드: - 병합: 기존 엔터티를 대체하지 않고 엔터티의 속성을 업데이트하여 엔터티를 업데이트합니다. - 바꾸기: 전체 엔터티를 대체하여 기존 엔터티를 업데이트합니다.

options
UpdateTableEntityOptions

옵션 매개 변수입니다.

엔터티 업데이트 예제

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const entity = { partitionKey: "p1", rowKey: "r1", bar: "updatedBar" };

// Update uses update mode "Merge" as default
// merge means that update will match a stored entity
// that has the same partitionKey and rowKey as the entity
// passed to the method and then will only update the properties present in it.
// Any other properties that are not defined in the entity passed to updateEntity
// will remain as they are in the service
await client.updateEntity(entity);

// We can also set the update mode to Replace, which will match the entity passed
// to updateEntity with one stored in the service and replace with the new one.
// If there are any missing properties in the entity passed to updateEntity, they
// will be removed from the entity stored in the service
await client.updateEntity(entity, "Replace");

반환

upsertEntity<T>(TableEntity<T>, UpdateMode, OperationOptions)

테이블의 엔터티를 Upsert합니다.

function upsertEntity<T>(entity: TableEntity<T>, mode?: UpdateMode, options?: OperationOptions): Promise<TableMergeEntityHeaders>

매개 변수

entity

TableEntity<T>

테이블 엔터티의 속성입니다.

mode
UpdateMode

엔터티를 업데이트하는 다양한 모드: - 병합: 기존 엔터티를 대체하지 않고 엔터티의 속성을 업데이트하여 엔터티를 업데이트합니다. - 바꾸기: 전체 엔터티를 대체하여 기존 엔터티를 업데이트합니다.

options
OperationOptions

옵션 매개 변수입니다.

엔터티를 업서팅하는 예제

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const entity = { partitionKey: "p1", rowKey: "r1", bar: "updatedBar" };

// Upsert uses update mode "Merge" as default.
// This behaves similarly to update but creates the entity
// if it doesn't exist in the service
await client.upsertEntity(entity);

// We can also set the update mode to Replace.
// This behaves similarly to update but creates the entity
// if it doesn't exist in the service
await client.upsertEntity(entity, "Replace");

반환