pub struct CosmosDbDocument(/* private fields */);
Expand description
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()
)
}
Implementations§
Source§impl CosmosDbDocument
impl CosmosDbDocument
Sourcepub fn new(value: Value) -> CosmosDbDocument
pub fn new(value: Value) -> CosmosDbDocument
Creates a new CosmosDbDocument
from a JSON object value.
The value must be a JSON object.
Sourcepub fn is_null(&self) -> bool
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.
Trait Implementations§
Source§impl Clone for CosmosDbDocument
impl Clone for CosmosDbDocument
Source§fn clone(&self) -> CosmosDbDocument
fn clone(&self) -> CosmosDbDocument
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for CosmosDbDocument
impl Debug for CosmosDbDocument
Source§impl Display for CosmosDbDocument
impl Display for CosmosDbDocument
Source§impl<'a> From<&'a str> for CosmosDbDocument
impl<'a> From<&'a str> for CosmosDbDocument
Source§impl From<String> for CosmosDbDocument
impl From<String> for CosmosDbDocument
Source§impl From<Value> for CosmosDbDocument
impl From<Value> for CosmosDbDocument
Source§impl<'a> Into<Body<'a>> for CosmosDbDocument
impl<'a> Into<Body<'a>> for CosmosDbDocument
Source§impl Into<String> for CosmosDbDocument
impl Into<String> for CosmosDbDocument
Auto Trait Implementations§
impl Freeze for CosmosDbDocument
impl RefUnwindSafe for CosmosDbDocument
impl Send for CosmosDbDocument
impl Sync for CosmosDbDocument
impl Unpin for CosmosDbDocument
impl UnwindSafe for CosmosDbDocument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request