Struct CosmosDbDocument

Source
pub struct CosmosDbDocument(/* private fields */);
Expand description

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()
    )
}

Implementations§

Source§

impl CosmosDbDocument

Source

pub fn new(value: Value) -> CosmosDbDocument

Creates a new CosmosDbDocument from a JSON object value.

The value must be a JSON object.

Source

pub fn is_null(&self) -> bool

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.

Source

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

Gets the JSON object for the Cosmos DB document

Returns None if the document is null.

Source

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

Gets a mutable JSON object for the Cosmos DB document

Returns None if the document is null.

Trait Implementations§

Source§

impl Clone for CosmosDbDocument

Source§

fn clone(&self) -> CosmosDbDocument

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CosmosDbDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for CosmosDbDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a str> for CosmosDbDocument

Source§

fn from(json: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for CosmosDbDocument

Source§

fn from(json: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for CosmosDbDocument

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl<'a> Into<Body<'a>> for CosmosDbDocument

Source§

fn into(self) -> Body<'a>

Converts this type into the (usually inferred) input type.
Source§

impl Into<String> for CosmosDbDocument

Source§

fn into(self) -> String

Converts this type into the (usually inferred) input type.
Source§

impl Into<Value> for CosmosDbDocument

Source§

fn into(self) -> Value

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more