pub struct SetBuilder<'a, E: TitoEngine, T: TitoModelConstraints> { /* private fields */ }Implementations§
Source§impl<'a, E: TitoEngine, T: TitoModelConstraints> SetBuilder<'a, E, T>
impl<'a, E: TitoEngine, T: TitoModelConstraints> SetBuilder<'a, E, T>
pub fn timestamps(self, timestamps: bool) -> Self
Sourcepub async fn execute(self, tx: &E::Transaction) -> Result<T, TitoError>
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
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>where
T: RefUnwindSafe,
E: RefUnwindSafe,
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> 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> 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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§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