[][src]Struct azure_functions::bindings::CosmosDbDocument

pub struct CosmosDbDocument(_);

Represents the input or output binding for a Cosmos DB document.

The following binding attributes are supported:

NameDescription
nameThe name of the parameter being bound.
database_nameThe database containing the document.
collection_nameThe name of the collection that contains the document.
idThe identifier of the document to retrieve. This attribute supports binding expressions. Cannot be used with sql_query. If neither are specified, the entire collection is retrieved.
sql_queryAn Azure Cosmos DB SQL query used for retrieving multiple documents. Cannot be used with id. If neither are specified, the entire collection is retrieved.
connectionThe name of the app setting containing your Azure Cosmos DB connection string.
partition_keySpecifies the partition key value for the lookup; may include binding parameters (input only). When create_collection is true, defines the partition key path for the created collection (output only).
create_collectionSpecifies if the collection should be created (output only).
collection_throughputWhen create_collection is true, defines the throughput of the created collection (output only).

Examples

Using CosmosDbDocument as an input binding with a SQL query:

use azure_functions::{
    bindings::{CosmosDbDocument, HttpRequest, HttpResponse},
    func,
};

#[func]
#[binding(
    name = "documents",
    connection = "myconnection",
    database_name = "mydb",
    collection_name = "mycollection",
    sql_query = "select * from mycollection c where startswith(c.name, 'peter')",
)]
pub fn read_documents(_req: HttpRequest, documents: Vec<CosmosDbDocument>) -> HttpResponse {
    documents.into()
}

Using CosmosDbDocument as an input binding for a specific document:

use azure_functions::{
    bindings::{CosmosDbDocument, HttpRequest, HttpResponse},
    func,
};

#[func]
#[binding(name = "_req", route = "read/{id}")]
#[binding(
    name = "document",
    connection = "myconnection",
    database_name = "mydb",
    collection_name = "mycollection",
    id = "{id}",
)]
pub fn read_document(_req: HttpRequest, document: CosmosDbDocument) -> HttpResponse {
    document.into()
}

Using CosmosDbDocument as an output binding:

use azure_functions::{
    bindings::{CosmosDbDocument, HttpRequest, HttpResponse},
    func,
};

#[func]
#[binding(
    name = "output1",
    connection = "myconnection",
    database_name = "mydb",
    collection_name = "mycollection"
)]
pub fn create_document(_req: HttpRequest) -> (HttpResponse, CosmosDbDocument) {
    (
        "Document created.".into(),
        json!({
            "id": "myid",
            "name": "Peter",
            "subject": "example"
        }).into()
    )
}

Methods

impl CosmosDbDocument[src]

pub fn new(value: Value) -> CosmosDbDocument[src]

Creates a new CosmosDbDocument from a JSON object value.

The value must be a JSON object.

pub fn is_null(&self) -> bool[src]

Gets whether or not the Cosmos DB document is null.

A Cosmos DB document can be null as a result of a query that returned no documents.

pub fn as_object(&self) -> Option<&Map<String, Value>>[src]

Gets the JSON object for the Cosmos DB document

Returns None if the document is null.

pub fn as_object_mut(&mut self) -> Option<&mut Map<String, Value>>[src]

Gets a mutable JSON object for the Cosmos DB document

Returns None if the document is null.

Trait Implementations

impl<'a> From<&'a str> for CosmosDbDocument[src]

impl From<String> for CosmosDbDocument[src]

impl From<Value> for CosmosDbDocument[src]

impl Clone for CosmosDbDocument[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Into<String> for CosmosDbDocument[src]

impl Into<Value> for CosmosDbDocument[src]

impl<'a> Into<Body<'a>> for CosmosDbDocument[src]

impl Display for CosmosDbDocument[src]

impl Debug for CosmosDbDocument[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> Erased for T