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

Source

pub fn new(url: &'static str) -> Self

Creates a new empty batch with its own batch id and dataset id

Source

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

Source

pub fn get_batch_id(&self) -> Uuid

returns the current batch id (This will change after a call to reset())

Source

pub fn get_dataset_id(&self) -> Uuid

returns the current dataset id (This will change after a call to reset())

Source

pub fn get_count(&self) -> u16

returns the current count of requests in this batch

Source

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,
        )
    }
}
Source

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,
        )
    }
}
Source

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,
        )
    }
}
Source

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§

Source§

impl Display for Batch

Source§

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

Formats the value using the given formatter. Read more

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> 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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,