Aracılığıyla paylaş


UserDefinedFunctions class

Tüm Kullanıcı Tanımlı İşlevleri oluşturmak, eklemek, sorgulamak veya okumak için kullanılır.

Belirli bir Kullanıcı Tanımlı İşlevi kimliğe göre okumak, değiştirmek veya silmek için userDefinedFunction bakın.

Özellikler

container

Yöntemler

create(UserDefinedFunctionDefinition, RequestOptions)

UserDefinedFunction oluşturun.

Azure Cosmos DB sorgular, saklı yordamlar ve tetikleyiciler içinde kullanılabilen JavaScript UDF'lerini destekler.

Ek ayrıntılar için sunucu tarafı JavaScript API belgelerine bakın.

Örnek

import { CosmosClient, UserDefinedFunctionDefinition } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const udfDefinition: UserDefinedFunctionDefinition = {
  id: "sample udf",
  body: "function () { const x = 10; }",
};

const { resource: udf } = await container.scripts.userDefinedFunctions.create(udfDefinition);
query(SqlQuerySpec, FeedOptions)

Tüm Kullanıcı Tanımlı İşlevleri sorgulayın.

query<T>(SqlQuerySpec, FeedOptions)

Tüm Kullanıcı Tanımlı İşlevleri sorgulayın.

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const querySpec = {
  query: "SELECT * FROM root r WHERE r.id=@id",
  parameters: [
    {
      name: "@id",
      value: "<udf-id>",
    },
  ],
};
const { resources: results } = await container.scripts.userDefinedFunctions
  .query(querySpec)
  .fetchAll();
readAll(FeedOptions)

Tüm Kullanıcı Tanımlı İşlevleri okuyun.

Örnek

Dizi için tüm Kullanıcı Tanımlı İşlevleri okuyun.

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resources: udfList } = await container.scripts.userDefinedFunctions.readAll().fetchAll();

Özellik Ayrıntıları

container

container: Container

Özellik Değeri

Yöntem Ayrıntıları

create(UserDefinedFunctionDefinition, RequestOptions)

UserDefinedFunction oluşturun.

Azure Cosmos DB sorgular, saklı yordamlar ve tetikleyiciler içinde kullanılabilen JavaScript UDF'lerini destekler.

Ek ayrıntılar için sunucu tarafı JavaScript API belgelerine bakın.

Örnek

import { CosmosClient, UserDefinedFunctionDefinition } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const udfDefinition: UserDefinedFunctionDefinition = {
  id: "sample udf",
  body: "function () { const x = 10; }",
};

const { resource: udf } = await container.scripts.userDefinedFunctions.create(udfDefinition);
function create(body: UserDefinedFunctionDefinition, options?: RequestOptions): Promise<UserDefinedFunctionResponse>

Parametreler

options
RequestOptions

Döndürülenler

query(SqlQuerySpec, FeedOptions)

Tüm Kullanıcı Tanımlı İşlevleri sorgulayın.

function query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<any>

Parametreler

query
SqlQuerySpec

İşlem için sorgu yapılandırması. Sorgu yapılandırma hakkında daha fazla bilgi için bkz. SqlQuerySpec.

options
FeedOptions

Döndürülenler

query<T>(SqlQuerySpec, FeedOptions)

Tüm Kullanıcı Tanımlı İşlevleri sorgulayın.

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const querySpec = {
  query: "SELECT * FROM root r WHERE r.id=@id",
  parameters: [
    {
      name: "@id",
      value: "<udf-id>",
    },
  ],
};
const { resources: results } = await container.scripts.userDefinedFunctions
  .query(querySpec)
  .fetchAll();
function query<T>(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<T>

Parametreler

query
SqlQuerySpec

İşlem için sorgu yapılandırması. Sorgu yapılandırma hakkında daha fazla bilgi için bkz. SqlQuerySpec.

options
FeedOptions

Döndürülenler

readAll(FeedOptions)

Tüm Kullanıcı Tanımlı İşlevleri okuyun.

Örnek

Dizi için tüm Kullanıcı Tanımlı İşlevleri okuyun.

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resources: udfList } = await container.scripts.userDefinedFunctions.readAll().fetchAll();
function readAll(options?: FeedOptions): QueryIterator<UserDefinedFunctionDefinition & Resource>

Parametreler

options
FeedOptions

Döndürülenler