Skip to main content

SetBuilder

Struct SetBuilder 

Source
pub struct SetBuilder<'a, E: TitoEngine, T: TitoModelConstraints> { /* private fields */ }

Implementations§

Source§

impl<'a, E: TitoEngine, T: TitoModelConstraints> SetBuilder<'a, E, T>

Source

pub fn timestamps(self, timestamps: bool) -> Self

Source

pub async fn execute(self, tx: &E::Transaction) -> Result<T, TitoError>

Examples found in repository?
examples/crud.rs (line 52)
38async fn main() -> Result<(), TitoError> {
39    let tito_db = TiKV::connect(vec!["127.0.0.1:2379"]).await?;
40    let user_model = tito_db.clone().model::<User>(TitoModelOptions::default());
41
42    let user_id = DBUuid::new_v4().to_string();
43    let user = User {
44        id: user_id.clone(),
45        name: "John Doe".to_string(),
46        email: "john@example.com".to_string(),
47    };
48
49    let saved_user = tito_db
50        .transaction(|tx| {
51            let user_model = user_model.clone();
52            async move { user_model.set(user).execute(&tx).await }
53        })
54        .await?;
55
56    println!("Created user: {:?}", saved_user);
57
58    let found_user = user_model.get(&user_id).execute(None).await?;
59    println!("Found user: {:?}", found_user);
60
61    let updated_user = User {
62        id: user_id.clone(),
63        name: "John Updated".to_string(),
64        email: "john_updated@example.com".to_string(),
65    };
66
67    tito_db
68        .transaction(|tx| {
69            let user_model = user_model.clone();
70            async move { user_model.set(updated_user).execute(&tx).await }
71        })
72        .await?;
73
74    println!("User updated");
75
76    tito_db
77        .transaction(|tx| {
78            let user_model = user_model.clone();
79            async move { user_model.remove(&user_id, &tx).await }
80        })
81        .await?;
82
83    println!("User deleted");
84
85    Ok(())
86}
More examples
Hide additional examples
examples/blog.rs (line 104)
88async fn main() -> Result<(), TitoError> {
89    let tito_db = TiKV::connect(vec!["127.0.0.1:2379"]).await?;
90
91    let post_model = tito_db.clone().model::<Post>(TitoModelOptions::default());
92    let tag_model = tito_db.clone().model::<Tag>(TitoModelOptions::default());
93
94    let tech_tag = tito_db
95        .transaction(|tx| {
96            let tag_model = tag_model.clone();
97            let tag = Tag {
98                id: DBUuid::new_v4().to_string(),
99                name: "Technology".to_string(),
100                description: "All about tech".to_string(),
101            };
102            let tag_clone = tag.clone();
103            async move {
104                tag_model.set(tag_clone).execute(&tx).await?;
105                Ok::<_, TitoError>(tag)
106            }
107        })
108        .await?;
109
110    let rust_tag = tito_db
111        .transaction(|tx| {
112            let tag_model = tag_model.clone();
113            let tag = Tag {
114                id: DBUuid::new_v4().to_string(),
115                name: "Rust".to_string(),
116                description: "Rust programming".to_string(),
117            };
118            let tag_clone = tag.clone();
119            async move {
120                tag_model.set(tag_clone).execute(&tx).await?;
121                Ok::<_, TitoError>(tag)
122            }
123        })
124        .await?;
125
126    println!("Created tags: {}, {}", tech_tag.name, rust_tag.name);
127
128    let post = tito_db
129        .transaction(|tx| {
130            let post_model = post_model.clone();
131            let post = Post {
132                id: DBUuid::new_v4().to_string(),
133                title: "Using Rust with TiKV".to_string(),
134                content: "Examples of using Rust with TiKV...".to_string(),
135                author: "Alice".to_string(),
136                tag_ids: vec![tech_tag.id.clone(), rust_tag.id.clone()],
137                tags: Vec::new(),
138            };
139            let post_clone = post.clone();
140            async move {
141                post_model.set(post_clone).execute(&tx).await?;
142                Ok::<_, TitoError>(post)
143            }
144        })
145        .await?;
146
147    println!("Created post: {}", post.title);
148
149    let post_with_tags = post_model
150        .get(&post.id)
151        .relationship("tags")
152        .execute(None)
153        .await?;
154
155    println!("Post: {}", post_with_tags.title);
156    println!("Tags:");
157    for tag in &post_with_tags.tags {
158        println!("- {}", tag.name);
159    }
160
161    let mut query = post_model.query_by_index("post-by-author");
162    let results = query
163        .value("Alice".to_string())
164        .relationship("tags")
165        .execute(None)
166        .await?;
167
168    println!("\nAlice's posts:");
169    for p in &results.items {
170        println!(
171            "- {} (tags: {})",
172            p.title,
173            p.tags
174                .iter()
175                .map(|t| t.name.clone())
176                .collect::<Vec<_>>()
177                .join(", ")
178        );
179    }
180
181    Ok(())
182}

Auto Trait Implementations§

§

impl<'a, E, T> Freeze for SetBuilder<'a, E, T>
where T: Freeze,

§

impl<'a, E, T> RefUnwindSafe for SetBuilder<'a, E, T>

§

impl<'a, E, T> Send for SetBuilder<'a, E, T>

§

impl<'a, E, T> Sync for SetBuilder<'a, E, T>

§

impl<'a, E, T> Unpin for SetBuilder<'a, E, T>

§

impl<'a, E, T> UnsafeUnpin for SetBuilder<'a, E, T>
where T: UnsafeUnpin,

§

impl<'a, E, T> UnwindSafe for SetBuilder<'a, E, T>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
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,