DataWeb
Search Results for

    Show / Hide Table of Contents

    Interface ICosmosHelper

    Cosmos DB data access helper for query execution, result mapping, and document mutations via SQL API.

    Namespace: DataWeb.Data.AzureCosmosDB
    Assembly: DataWeb.Data.AzureCosmosDB.dll
    Syntax
    public interface ICosmosHelper

    Methods

    AddArrayValueAsync(string, string, object, string, string, string, CosmosClient, CancellationToken)

    Appends an element to an array field in a document using the Cosmos DB patch API.

    Declaration
    Task AddArrayValueAsync(string id, string arrayFieldPath, object value, string storageDatabase, string storageContainer, string partitionKey, CosmosClient client = null, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    string id
    string arrayFieldPath

    JSON path to the array property (e.g., '/tags').

    object value
    string storageDatabase
    string storageContainer
    string partitionKey
    CosmosClient client
    CancellationToken cancellationToken
    Returns
    Type Description
    Task

    DeleteItemAsync<T>(string, string, string, string, CosmosClient, CancellationToken)

    Deletes a document from Cosmos DB by ID and partition key.

    Declaration
    Task DeleteItemAsync<T>(string id, string storageDatabase, string storageContainer, string partitionKey, CosmosClient client = null, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    string id
    string storageDatabase
    string storageContainer
    string partitionKey
    CosmosClient client
    CancellationToken cancellationToken
    Returns
    Type Description
    Task
    Type Parameters
    Name Description
    T

    DeleteItemsAsync<T>(IEnumerable<(string id, string partitionKey)>, string, string, CosmosClient, CancellationToken)

    Deletes multiple documents from Cosmos DB in parallel.

    Declaration
    Task DeleteItemsAsync<T>(IEnumerable<(string id, string partitionKey)> items, string storageDatabase, string storageContainer, CosmosClient client = null, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    IEnumerable<(string id, string partitionKey)> items

    Collection of (id, partitionKey) pairs to delete.

    string storageDatabase
    string storageContainer
    CosmosClient client
    CancellationToken cancellationToken
    Returns
    Type Description
    Task
    Type Parameters
    Name Description
    T

    GetListAsync<T>(Query, string, string, CosmosClient, CancellationToken)

    Executes a query and returns a collection of mapped results. Overload accepting a pre-compiled Query object.

    Declaration
    Task<IReadOnlyList<T>> GetListAsync<T>(Query query, string storageDatabase, string storageContainer, CosmosClient client = null, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    Query query
    string storageDatabase
    string storageContainer
    CosmosClient client
    CancellationToken cancellationToken
    Returns
    Type Description
    Task<IReadOnlyList<T>>
    Type Parameters
    Name Description
    T

    GetListAsync<T>(string, string, string, Dictionary<string, object>, int, long?, CosmosClient, CancellationToken)

    Executes a query and returns a collection of mapped results with optional pagination.

    Declaration
    Task<IReadOnlyList<T>> GetListAsync<T>(string query, string storageDatabase, string storageContainer, Dictionary<string, object> parameters = null, int count = 0, long? pageIndex = null, CosmosClient client = null, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    string query
    string storageDatabase
    string storageContainer
    Dictionary<string, object> parameters
    int count

    Max documents to return. 0 = all.

    long? pageIndex

    0-based page number. If null, uses count-based retrieval.

    CosmosClient client
    CancellationToken cancellationToken
    Returns
    Type Description
    Task<IReadOnlyList<T>>
    Type Parameters
    Name Description
    T

    GetValueAsync<T>(Query, string, string, CosmosClient, CancellationToken)

    Executes a scalar query and returns a single mapped value. Overload accepting a pre-compiled Query object.

    Declaration
    Task<T> GetValueAsync<T>(Query query, string storageDatabase, string storageContainer, CosmosClient client = null, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    Query query
    string storageDatabase
    string storageContainer
    CosmosClient client
    CancellationToken cancellationToken
    Returns
    Type Description
    Task<T>
    Type Parameters
    Name Description
    T

    GetValueAsync<T>(string, string, string, Dictionary<string, object>, CosmosClient, CancellationToken)

    Executes a scalar query and returns a single mapped value. Uses MaxItemCount=1 for efficiency.

    Declaration
    Task<T> GetValueAsync<T>(string query, string storageDatabase, string storageContainer, Dictionary<string, object> parameters = null, CosmosClient client = null, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    string query
    string storageDatabase
    string storageContainer
    Dictionary<string, object> parameters
    CosmosClient client
    CancellationToken cancellationToken
    Returns
    Type Description
    Task<T>

    First result, or default(T) if empty.

    Type Parameters
    Name Description
    T

    IncrementValueAsync(string, string, long, string, string, string, CosmosClient, CancellationToken)

    Atomically increments a numeric field in a document using the Cosmos DB patch API.

    Declaration
    Task<long> IncrementValueAsync(string id, string fieldPath, long incrementValue, string storageDatabase, string storageContainer, string partitionKey, CosmosClient client = null, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    string id
    string fieldPath

    JSON path to the numeric property (e.g., '/count').

    long incrementValue
    string storageDatabase
    string storageContainer
    string partitionKey
    CosmosClient client
    CancellationToken cancellationToken
    Returns
    Type Description
    Task<long>

    The new value after the increment.

    SetValueAsync(string, string, object, string, string, string, CosmosClient, CancellationToken)

    Patches a single property of an existing document using the Cosmos DB patch API.

    Declaration
    Task SetValueAsync(string id, string fieldPath, object value, string storageDatabase, string storageContainer, string partitionKey, CosmosClient client = null, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    string id
    string fieldPath

    JSON path to the property (e.g., '/status').

    object value
    string storageDatabase
    string storageContainer
    string partitionKey
    CosmosClient client
    CancellationToken cancellationToken
    Returns
    Type Description
    Task

    UpsertDictionaryAsync(Dictionary<string, object>, string, string, string, CosmosClient, CancellationToken)

    Inserts or updates a dictionary-based document in Cosmos DB. Data must contain an 'Id' or 'id' key.

    Declaration
    Task UpsertDictionaryAsync(Dictionary<string, object> data, string storageDatabase, string storageContainer, string partitionKey, CosmosClient client = null, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    Dictionary<string, object> data
    string storageDatabase
    string storageContainer
    string partitionKey
    CosmosClient client
    CancellationToken cancellationToken
    Returns
    Type Description
    Task

    UpsertItemAsync<T>(T, string, string, string, CosmosClient, CancellationToken)

    Inserts or updates a strongly-typed item in Cosmos DB.

    Declaration
    Task UpsertItemAsync<T>(T item, string storageDatabase, string storageContainer, string partitionKey, CosmosClient client = null, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    T item
    string storageDatabase
    string storageContainer
    string partitionKey
    CosmosClient client
    CancellationToken cancellationToken
    Returns
    Type Description
    Task
    Type Parameters
    Name Description
    T
    In this article
    Back to top Generated by DocFX