[−][src]Struct azure_functions::bindings::CosmosDbDocument
Represents the input or output binding for a Cosmos DB document.
The following binding attributes are supported:
Name | Description |
---|---|
name | The name of the parameter being bound. |
database_name | The database containing the document. |
collection_name | The name of the collection that contains the document. |
id | The 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_query | An Azure Cosmos DB SQL query used for retrieving multiple documents. Cannot be used with id . If neither are specified, the entire collection is retrieved. |
connection | The name of the app setting containing your Azure Cosmos DB connection string. |
partition_key | Specifies 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_collection | Specifies if the collection should be created (output only). |
collection_throughput | When 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 Into<String> for CosmosDbDocument
[src]
impl Into<Value> for CosmosDbDocument
[src]
impl<'a> Into<Body<'a>> for CosmosDbDocument
[src]
impl Clone for CosmosDbDocument
[src]
fn clone(&self) -> CosmosDbDocument
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'a> From<&'a str> for CosmosDbDocument
[src]
impl From<String> for CosmosDbDocument
[src]
impl From<Value> for CosmosDbDocument
[src]
impl Debug for CosmosDbDocument
[src]
impl Display for CosmosDbDocument
[src]
Auto Trait Implementations
impl Send for CosmosDbDocument
impl Sync for CosmosDbDocument
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,