pub struct Batch { /* private fields */ }
Expand description
Represents a batch of Microsoft Dataverse Requests
Some restrictions apply for creating batches:
- the batch size may not exceed 1000 calls
- the batch execution time may not exceed 2 minutes
the second restriction is especially tricky to handle because the execution time depends on the complexity of the entity in dataverse. So it is possible to create 300 records of an entity with low complexity but only 50 records of an entity with high complexity in that timeframe.
Based on experience a batch size of 50 should be safe for all entities though
§Examples
use uuid::Uuid;
use serde::Serialize;
use powerplatform_dataverse_service_client::{
batch::Batch,
client::Client,
entity::WriteEntity,
reference::{Reference, ReferenceStruct},
result::{Result, IntoDataverseResult}
};
async fn test() -> Result<()> {
let testy_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789012").into_dataverse_result()?,
firstname: String::from("Testy"),
lastname: String::from("McTestface"),
};
let marianne_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789abc").into_dataverse_result()?,
firstname: String::from("Marianne"),
lastname: String::from("McTestface"),
};
// this batch creates both contacts in one call
let mut batch = Batch::new("https://instance.crm.dynamics.com/");
batch.create(&testy_contact)?;
batch.create(&marianne_contact)?;
let client = Client::new_dummy(); // Please replace this with your preferred authentication method
client.execute(&batch).await?;
Ok(())
}
#[derive(Serialize)]
struct Contact {
contactid: Uuid,
firstname: String,
lastname: String,
}
impl WriteEntity for Contact {}
impl Reference for Contact {
fn get_reference(&self) -> ReferenceStruct {
ReferenceStruct::new(
"contacts",
self.contactid,
)
}
}
Implementations§
Source§impl Batch
impl Batch
Sourcepub fn new(url: &'static str) -> Self
pub fn new(url: &'static str) -> Self
Creates a new empty batch with its own batch id and dataset id
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Clears the batch of its contents and generates a new batch id and a new dataset id
Note that this can be used to prevent frequent allocations by reusing
the Batch
instance and its buffer
Sourcepub fn get_batch_id(&self) -> Uuid
pub fn get_batch_id(&self) -> Uuid
returns the current batch id (This will change after a call to reset()
)
Sourcepub fn get_dataset_id(&self) -> Uuid
pub fn get_dataset_id(&self) -> Uuid
returns the current dataset id (This will change after a call to reset()
)
Sourcepub fn create(&mut self, entity: &impl WriteEntity) -> Result<()>
pub fn create(&mut self, entity: &impl WriteEntity) -> Result<()>
Adds a Create Request for the given entity to this batch
Please note that this function can fail if a serde serialization error occurs
§Examples
use uuid::Uuid;
use serde::Serialize;
use powerplatform_dataverse_service_client::{
batch::Batch,
client::Client,
entity::WriteEntity,
reference::{Reference, ReferenceStruct},
result::{Result, IntoDataverseResult}
};
async fn test() -> Result<()> {
let testy_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789012").into_dataverse_result()?,
firstname: String::from("Testy"),
lastname: String::from("McTestface"),
};
let marianne_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789abc").into_dataverse_result()?,
firstname: String::from("Marianne"),
lastname: String::from("McTestface"),
};
// this batch creates both contacts in one call
let mut batch = Batch::new("https://instance.crm.dynamics.com/");
batch.create(&testy_contact)?;
batch.create(&marianne_contact)?;
let client = Client::new_dummy(); // Please replace this with your preferred authentication method
client.execute(&batch).await?;
Ok(())
}
#[derive(Serialize)]
struct Contact {
contactid: Uuid,
firstname: String,
lastname: String,
}
impl WriteEntity for Contact {}
impl Reference for Contact {
fn get_reference(&self) -> ReferenceStruct {
ReferenceStruct::new(
"contacts",
self.contactid,
)
}
}
Sourcepub fn update(&mut self, entity: &impl WriteEntity) -> Result<()>
pub fn update(&mut self, entity: &impl WriteEntity) -> Result<()>
Adds an Update Request for the given entity to this batch
Please note that this function can fail if a serde serialization error occurs
§Examples
use uuid::Uuid;
use serde::Serialize;
use powerplatform_dataverse_service_client::{
batch::Batch,
client::Client,
entity::WriteEntity,
reference::{Reference, ReferenceStruct},
result::{Result, IntoDataverseResult}
};
async fn test() -> Result<()> {
let testy_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789012").into_dataverse_result()?,
firstname: String::from("Testy"),
lastname: String::from("McTestface"),
};
let marianne_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789abc").into_dataverse_result()?,
firstname: String::from("Marianne"),
lastname: String::from("McTestface"),
};
// this batch creates both contacts in one call
let mut batch = Batch::new("https://instance.crm.dynamics.com/");
batch.update(&testy_contact)?;
batch.update(&marianne_contact)?;
let client = Client::new_dummy(); // Please replace this with your preferred authentication method
client.execute(&batch).await?;
Ok(())
}
#[derive(Serialize)]
struct Contact {
contactid: Uuid,
firstname: String,
lastname: String,
}
impl WriteEntity for Contact {}
impl Reference for Contact {
fn get_reference(&self) -> ReferenceStruct {
ReferenceStruct::new(
"contacts",
self.contactid,
)
}
}
Sourcepub fn upsert(&mut self, entity: &impl WriteEntity) -> Result<()>
pub fn upsert(&mut self, entity: &impl WriteEntity) -> Result<()>
Adds an Upsert Request for the given entity to this batch
Please note that this function can fail if a serde serialization error occurs
§Examples
use uuid::Uuid;
use serde::Serialize;
use powerplatform_dataverse_service_client::{
batch::Batch,
client::Client,
entity::WriteEntity,
reference::{Reference, ReferenceStruct},
result::{Result, IntoDataverseResult}
};
async fn test() -> Result<()> {
let testy_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789012").into_dataverse_result()?,
firstname: String::from("Testy"),
lastname: String::from("McTestface"),
};
let marianne_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789abc").into_dataverse_result()?,
firstname: String::from("Marianne"),
lastname: String::from("McTestface"),
};
// this batch creates both contacts in one call
let mut batch = Batch::new("https://instance.crm.dynamics.com/");
batch.upsert(&testy_contact)?;
batch.upsert(&marianne_contact)?;
let client = Client::new_dummy(); // Please replace this with your preferred authentication method
client.execute(&batch).await?;
Ok(())
}
#[derive(Serialize)]
struct Contact {
contactid: Uuid,
firstname: String,
lastname: String,
}
impl WriteEntity for Contact {}
impl Reference for Contact {
fn get_reference(&self) -> ReferenceStruct {
ReferenceStruct::new(
"contacts",
self.contactid,
)
}
}
Sourcepub fn delete(&mut self, entity: &impl Reference) -> Result<()>
pub fn delete(&mut self, entity: &impl Reference) -> Result<()>
Adds a Delete Request for the given entity reference to this batch
Please note that this function can fail if a serde serialization error occurs
§Examples
use uuid::Uuid;
use serde::Serialize;
use powerplatform_dataverse_service_client::{
batch::Batch,
client::Client,
entity::WriteEntity,
reference::{Reference, ReferenceStruct},
result::{Result, IntoDataverseResult}
};
async fn test() -> Result<()> {
let testy_contact = ReferenceStruct::new(
"contacts",
Uuid::parse_str("12345678-1234-1234-1234-123456789012").into_dataverse_result()?
);
let marianne_contact = ReferenceStruct::new(
"contacts",
Uuid::parse_str("12345678-1234-1234-1234-123456789abc").into_dataverse_result()?
);
// this batch creates both contacts in one call
let mut batch = Batch::new("https://instance.crm.dynamics.com/");
batch.delete(&testy_contact)?;
batch.delete(&marianne_contact)?;
let client = Client::new_dummy(); // Please replace this with your preferred authentication method
client.execute(&batch).await?;
Ok(())
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Batch
impl RefUnwindSafe for Batch
impl Send for Batch
impl Sync for Batch
impl Unpin for Batch
impl UnwindSafe for Batch
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
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.