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
let testy_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789012").unwrap(),
firstname: String::from("Testy"),
lastname: String::from("McTestface"),
};
let marianne_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789abc").unwrap(),
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).unwrap();
batch.create(&marianne_contact).unwrap();
client.execute(&batch).unwrap();
#[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
sourceimpl 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 can change after a call to reset() though)
sourcepub fn get_dataset_id(&self) -> Uuid
pub fn get_dataset_id(&self) -> Uuid
returns the current dataset id (This can change after a call to reset() though)
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
let testy_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789012").unwrap(),
firstname: String::from("Testy"),
lastname: String::from("McTestface"),
};
let marianne_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789abc").unwrap(),
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).unwrap();
batch.create(&marianne_contact).unwrap();
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
let testy_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789012").unwrap(),
firstname: String::from("Testy"),
lastname: String::from("McTestface"),
};
let marianne_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789abc").unwrap(),
firstname: String::from("Marianne"),
lastname: String::from("McTestface"),
};
// this batch updates both contacts in one call
let mut batch = Batch::new("https://instance.crm.dynamics.com/");
batch.update(&testy_contact).unwrap();
batch.update(&marianne_contact).unwrap();
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
let testy_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789012").unwrap(),
firstname: String::from("Testy"),
lastname: String::from("McTestface"),
};
let marianne_contact = Contact {
contactid: Uuid::parse_str("12345678-1234-1234-1234-123456789abc").unwrap(),
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).unwrap();
batch.upsert(&marianne_contact).unwrap();
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
let testy_reference = ReferenceStruct::new(
"contacts",
Uuid::parse_str("12345678-1234-1234-1234-123456789012").unwrap()
);
let marianne_reference = ReferenceStruct::new(
"contacts",
Uuid::parse_str("12345678-1234-1234-1234-123456789abc").unwrap()
);
// this batch creates both contacts in one call
let mut batch = Batch::new("https://instance.crm.dynamics.com/");
batch.delete(&testy_reference).unwrap();
batch.delete(&marianne_reference).unwrap();
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Batch
impl Send for Batch
impl Sync for Batch
impl Unpin for Batch
impl UnwindSafe for Batch
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more