TitoModel

Struct TitoModel 

Source
pub struct TitoModel<E: TitoEngine, T> {
    pub model: T,
    pub engine: E,
}

Fields§

§model: T§engine: E

Implementations§

Source§

impl<E: TitoEngine, T: TitoModelConstraints> TitoModel<E, T>

Source

pub fn get_embedded_relationships(&self) -> Vec<TitoEmbeddedRelationshipConfig>

Source

pub fn get_table(&self) -> String

Source

pub fn get_id_from_table(&self, key: String) -> String

Source

pub fn query_by_index( &self, index: impl Into<String>, ) -> IndexQueryBuilder<E, T>

Examples found in repository?
examples/blog.rs (line 288)
123async fn main() -> Result<(), TitoError> {
124    // Connect to TiKV
125    let tito_db = TiKV::connect(vec!["127.0.0.1:2379"]).await?;
126
127    // Create models
128    let post_model = tito_db.clone().model::<Post>();
129    let tag_model = tito_db.clone().model::<Tag>();
130
131    // Create some tags
132    let tech_tag = tito_db
133        .transaction(|tx| {
134            let tag_model = tag_model.clone();
135            let tag = Tag {
136                id: DBUuid::new_v4().to_string(),
137                name: "Technology".to_string(),
138                description: "All about tech".to_string(),
139            };
140            let tag_clone = tag.clone();
141
142            async move {
143                tag_model.build(tag_clone, &tx).await?;
144                Ok::<_, TitoError>(tag)
145            }
146        })
147        .await?;
148
149    let travel_tag = tito_db
150        .transaction(|tx| {
151            let tag_model = tag_model.clone();
152            let tag = Tag {
153                id: DBUuid::new_v4().to_string(),
154                name: "Travel".to_string(),
155                description: "Adventures around the world".to_string(),
156            };
157            let tag_clone = tag.clone();
158
159            async move {
160                tag_model.build(tag_clone, &tx).await?;
161                Ok::<_, TitoError>(tag)
162            }
163        })
164        .await?;
165
166    let rust_tag = tito_db
167        .transaction(|tx| {
168            let tag_model = tag_model.clone();
169            let tag = Tag {
170                id: DBUuid::new_v4().to_string(),
171                name: "Rust".to_string(),
172                description: "Rust programming language".to_string(),
173            };
174            let tag_clone = tag.clone();
175
176            async move {
177                tag_model.build(tag_clone, &tx).await?;
178                Ok::<_, TitoError>(tag)
179            }
180        })
181        .await?;
182
183    let database_tag = tito_db
184        .transaction(|tx| {
185            let tag_model = tag_model.clone();
186            let tag = Tag {
187                id: DBUuid::new_v4().to_string(),
188                name: "Databases".to_string(),
189                description: "Database systems and technologies".to_string(),
190            };
191            let tag_clone = tag.clone();
192
193            async move {
194                tag_model.build(tag_clone, &tx).await?;
195                Ok::<_, TitoError>(tag)
196            }
197        })
198        .await?;
199
200    println!("Created tags:");
201    println!("- {}: {}", tech_tag.name, tech_tag.id);
202    println!("- {}: {}", travel_tag.name, travel_tag.id);
203    println!("- {}: {}", rust_tag.name, rust_tag.id);
204    println!("- {}: {}", database_tag.name, database_tag.id);
205
206    // Create some posts with multiple tags
207    let post1 = tito_db
208        .transaction(|tx| {
209            let post_model = post_model.clone();
210            let post = Post {
211                id: DBUuid::new_v4().to_string(),
212                title: "Introduction to TiKV".to_string(),
213                content: "TiKV is a distributed key-value storage system...".to_string(),
214                author: "Alice".to_string(),
215                tag_ids: vec![tech_tag.id.clone(), database_tag.id.clone()],
216                tags: Vec::new(),
217            };
218            let post_clone = post.clone();
219
220            async move {
221                post_model.build(post_clone, &tx).await?;
222                Ok::<_, TitoError>(post)
223            }
224        })
225        .await?;
226
227    let post2 = tito_db
228        .transaction(|tx| {
229            let post_model = post_model.clone();
230            let post = Post {
231                id: DBUuid::new_v4().to_string(),
232                title: "Best cities to visit in Europe".to_string(),
233                content: "Europe offers a diverse range of cities...".to_string(),
234                author: "Bob".to_string(),
235                tag_ids: vec![travel_tag.id.clone()],
236                tags: Vec::new(),
237            };
238            let post_clone = post.clone();
239
240            async move {
241                post_model.build(post_clone, &tx).await?;
242                Ok::<_, TitoError>(post)
243            }
244        })
245        .await?;
246
247    let post3 = tito_db
248        .transaction(|tx| {
249            let post_model = post_model.clone();
250            let post = Post {
251                id: DBUuid::new_v4().to_string(),
252                title: "Using Rust with TiKV".to_string(),
253                content: "Here are some examples of using Rust with TiKV...".to_string(),
254                author: "Alice".to_string(),
255                tag_ids: vec![
256                    tech_tag.id.clone(),
257                    rust_tag.id.clone(),
258                    database_tag.id.clone(),
259                ],
260                tags: Vec::new(),
261            };
262            let post_clone = post.clone();
263
264            async move {
265                post_model.build(post_clone, &tx).await?;
266                Ok::<_, TitoError>(post)
267            }
268        })
269        .await?;
270
271    println!("\nCreated posts:");
272    println!("1. {} (by {})", post1.title, post1.author);
273    println!("2. {} (by {})", post2.title, post2.author);
274    println!("3. {} (by {})", post3.title, post3.author);
275
276    // Get a post with all its tags
277    let post_with_tags = post_model
278        .find_by_id(&post1.id, vec!["tags".to_string()])
279        .await?;
280    println!("\nPost with tags:");
281    println!("Title: {}", post_with_tags.title);
282    println!("Tags:");
283    for tag in &post_with_tags.tags {
284        println!("- {}", tag.name);
285    }
286
287    // Find posts by tag using the query builder
288    let mut tech_query = post_model.query_by_index("post-by-tag");
289    let tech_results = tech_query
290        .value(tech_tag.id.clone())
291        .relationship("tags")
292        .execute()
293        .await?;
294
295    println!("\nTechnology posts:");
296    for post in &tech_results.items {
297        println!("- {} (by {})", post.title, post.author);
298        println!(
299            "  Tags: {}",
300            post.tags
301                .iter()
302                .map(|t| t.name.clone())
303                .collect::<Vec<_>>()
304                .join(", ")
305        );
306    }
307
308    // Find posts by author using the query builder
309    let mut alice_query = post_model.query_by_index("post-by-author");
310    let alice_results = alice_query
311        .value("Alice".to_string())
312        .relationship("tags")
313        .execute()
314        .await?;
315
316    println!("\nAlice's posts:");
317    for post in &alice_results.items {
318        println!("- {}", post.title);
319        println!(
320            "  Tags: {}",
321            post.tags
322                .iter()
323                .map(|t| t.name.clone())
324                .collect::<Vec<_>>()
325                .join(", ")
326        );
327    }
328
329    Ok(())
330}
Source

pub async fn tx<F, Fut, R, Err>(&self, f: F) -> Result<R, Err>
where F: FnOnce(E::Transaction) -> Fut + Send, Fut: Future<Output = Result<R, Err>> + Send, Err: From<TitoError> + Send + Sync + Debug, R: Send,

Source

pub async fn get_key( &self, key: &str, tx: &E::Transaction, ) -> Result<Value, TitoError>

Source

pub async fn delete( &self, key: String, tx: &E::Transaction, ) -> Result<bool, TitoError>

Source

pub fn to_paginated_items_with_cursor( &self, items: Vec<(String, Value)>, cursor: String, ) -> Result<TitoPaginated<T>, TitoError>

Source

pub fn to_paginated_items( &self, items: Vec<(String, Value)>, has_more: bool, ) -> Result<TitoPaginated<T>, TitoError>

Source

pub fn get_nested_values( &self, json: &Value, field_path: &str, ) -> Option<Vec<Value>>

Source

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

Examples found in repository?
examples/crud.rs (line 68)
49async fn main() -> Result<(), TitoError> {
50    // Connect to TiKV
51    let tito_db = TiKV::connect(vec!["127.0.0.1:2379"]).await?;
52
53    // Create model with dynamic backend
54    let user_model = tito_db.clone().model::<User>();
55
56    // Create a user
57    let user_id = DBUuid::new_v4().to_string();
58    let user = User {
59        id: user_id.clone(),
60        name: "John Doe".to_string(),
61        email: "john@example.com".to_string(),
62    };
63
64    // Create user with transaction
65    let saved_user = tito_db
66        .transaction(|tx| {
67            let user_model = user_model.clone();
68            async move { user_model.build(user, &tx).await }
69        })
70        .await?;
71
72    println!("Created user: {:?}", saved_user);
73
74    // Find user (find_by_id already uses transaction internally)
75    let found_user = user_model.find_by_id(&user_id, vec![]).await?;
76    println!("Found user: {:?}", found_user);
77
78    // Update user
79    let updated_user = User {
80        id: user_id.clone(),
81        name: "John Updated".to_string(),
82        email: "john_updated@example.com".to_string(),
83    };
84
85    tito_db
86        .transaction(|tx| {
87            let user_model = user_model.clone();
88            async move { user_model.update(updated_user, &tx).await }
89        })
90        .await?;
91
92    println!("User updated successfully");
93
94    // Delete user
95    tito_db
96        .transaction(|tx| {
97            let user_model = user_model.clone();
98            async move { user_model.delete_by_id(&user_id, &tx).await }
99        })
100        .await?;
101
102    println!("User deleted successfully");
103
104    Ok(())
105}
More examples
Hide additional examples
examples/blog.rs (line 143)
123async fn main() -> Result<(), TitoError> {
124    // Connect to TiKV
125    let tito_db = TiKV::connect(vec!["127.0.0.1:2379"]).await?;
126
127    // Create models
128    let post_model = tito_db.clone().model::<Post>();
129    let tag_model = tito_db.clone().model::<Tag>();
130
131    // Create some tags
132    let tech_tag = tito_db
133        .transaction(|tx| {
134            let tag_model = tag_model.clone();
135            let tag = Tag {
136                id: DBUuid::new_v4().to_string(),
137                name: "Technology".to_string(),
138                description: "All about tech".to_string(),
139            };
140            let tag_clone = tag.clone();
141
142            async move {
143                tag_model.build(tag_clone, &tx).await?;
144                Ok::<_, TitoError>(tag)
145            }
146        })
147        .await?;
148
149    let travel_tag = tito_db
150        .transaction(|tx| {
151            let tag_model = tag_model.clone();
152            let tag = Tag {
153                id: DBUuid::new_v4().to_string(),
154                name: "Travel".to_string(),
155                description: "Adventures around the world".to_string(),
156            };
157            let tag_clone = tag.clone();
158
159            async move {
160                tag_model.build(tag_clone, &tx).await?;
161                Ok::<_, TitoError>(tag)
162            }
163        })
164        .await?;
165
166    let rust_tag = tito_db
167        .transaction(|tx| {
168            let tag_model = tag_model.clone();
169            let tag = Tag {
170                id: DBUuid::new_v4().to_string(),
171                name: "Rust".to_string(),
172                description: "Rust programming language".to_string(),
173            };
174            let tag_clone = tag.clone();
175
176            async move {
177                tag_model.build(tag_clone, &tx).await?;
178                Ok::<_, TitoError>(tag)
179            }
180        })
181        .await?;
182
183    let database_tag = tito_db
184        .transaction(|tx| {
185            let tag_model = tag_model.clone();
186            let tag = Tag {
187                id: DBUuid::new_v4().to_string(),
188                name: "Databases".to_string(),
189                description: "Database systems and technologies".to_string(),
190            };
191            let tag_clone = tag.clone();
192
193            async move {
194                tag_model.build(tag_clone, &tx).await?;
195                Ok::<_, TitoError>(tag)
196            }
197        })
198        .await?;
199
200    println!("Created tags:");
201    println!("- {}: {}", tech_tag.name, tech_tag.id);
202    println!("- {}: {}", travel_tag.name, travel_tag.id);
203    println!("- {}: {}", rust_tag.name, rust_tag.id);
204    println!("- {}: {}", database_tag.name, database_tag.id);
205
206    // Create some posts with multiple tags
207    let post1 = tito_db
208        .transaction(|tx| {
209            let post_model = post_model.clone();
210            let post = Post {
211                id: DBUuid::new_v4().to_string(),
212                title: "Introduction to TiKV".to_string(),
213                content: "TiKV is a distributed key-value storage system...".to_string(),
214                author: "Alice".to_string(),
215                tag_ids: vec![tech_tag.id.clone(), database_tag.id.clone()],
216                tags: Vec::new(),
217            };
218            let post_clone = post.clone();
219
220            async move {
221                post_model.build(post_clone, &tx).await?;
222                Ok::<_, TitoError>(post)
223            }
224        })
225        .await?;
226
227    let post2 = tito_db
228        .transaction(|tx| {
229            let post_model = post_model.clone();
230            let post = Post {
231                id: DBUuid::new_v4().to_string(),
232                title: "Best cities to visit in Europe".to_string(),
233                content: "Europe offers a diverse range of cities...".to_string(),
234                author: "Bob".to_string(),
235                tag_ids: vec![travel_tag.id.clone()],
236                tags: Vec::new(),
237            };
238            let post_clone = post.clone();
239
240            async move {
241                post_model.build(post_clone, &tx).await?;
242                Ok::<_, TitoError>(post)
243            }
244        })
245        .await?;
246
247    let post3 = tito_db
248        .transaction(|tx| {
249            let post_model = post_model.clone();
250            let post = Post {
251                id: DBUuid::new_v4().to_string(),
252                title: "Using Rust with TiKV".to_string(),
253                content: "Here are some examples of using Rust with TiKV...".to_string(),
254                author: "Alice".to_string(),
255                tag_ids: vec![
256                    tech_tag.id.clone(),
257                    rust_tag.id.clone(),
258                    database_tag.id.clone(),
259                ],
260                tags: Vec::new(),
261            };
262            let post_clone = post.clone();
263
264            async move {
265                post_model.build(post_clone, &tx).await?;
266                Ok::<_, TitoError>(post)
267            }
268        })
269        .await?;
270
271    println!("\nCreated posts:");
272    println!("1. {} (by {})", post1.title, post1.author);
273    println!("2. {} (by {})", post2.title, post2.author);
274    println!("3. {} (by {})", post3.title, post3.author);
275
276    // Get a post with all its tags
277    let post_with_tags = post_model
278        .find_by_id(&post1.id, vec!["tags".to_string()])
279        .await?;
280    println!("\nPost with tags:");
281    println!("Title: {}", post_with_tags.title);
282    println!("Tags:");
283    for tag in &post_with_tags.tags {
284        println!("- {}", tag.name);
285    }
286
287    // Find posts by tag using the query builder
288    let mut tech_query = post_model.query_by_index("post-by-tag");
289    let tech_results = tech_query
290        .value(tech_tag.id.clone())
291        .relationship("tags")
292        .execute()
293        .await?;
294
295    println!("\nTechnology posts:");
296    for post in &tech_results.items {
297        println!("- {} (by {})", post.title, post.author);
298        println!(
299            "  Tags: {}",
300            post.tags
301                .iter()
302                .map(|t| t.name.clone())
303                .collect::<Vec<_>>()
304                .join(", ")
305        );
306    }
307
308    // Find posts by author using the query builder
309    let mut alice_query = post_model.query_by_index("post-by-author");
310    let alice_results = alice_query
311        .value("Alice".to_string())
312        .relationship("tags")
313        .execute()
314        .await?;
315
316    println!("\nAlice's posts:");
317    for post in &alice_results.items {
318        println!("- {}", post.title);
319        println!(
320            "  Tags: {}",
321            post.tags
322                .iter()
323                .map(|t| t.name.clone())
324                .collect::<Vec<_>>()
325                .join(", ")
326        );
327    }
328
329    Ok(())
330}
Source

pub async fn build_with_options( &self, payload: T, options: TitoOptions, tx: &E::Transaction, ) -> Result<T, TitoError>

Source

pub async fn find_by_id_tx( &self, id: &str, rels: Vec<String>, tx: &E::Transaction, ) -> Result<T, TitoError>

Source

pub async fn find_by_id( &self, id: &str, rels: Vec<String>, ) -> Result<T, TitoError>

Examples found in repository?
examples/crud.rs (line 75)
49async fn main() -> Result<(), TitoError> {
50    // Connect to TiKV
51    let tito_db = TiKV::connect(vec!["127.0.0.1:2379"]).await?;
52
53    // Create model with dynamic backend
54    let user_model = tito_db.clone().model::<User>();
55
56    // Create a user
57    let user_id = DBUuid::new_v4().to_string();
58    let user = User {
59        id: user_id.clone(),
60        name: "John Doe".to_string(),
61        email: "john@example.com".to_string(),
62    };
63
64    // Create user with transaction
65    let saved_user = tito_db
66        .transaction(|tx| {
67            let user_model = user_model.clone();
68            async move { user_model.build(user, &tx).await }
69        })
70        .await?;
71
72    println!("Created user: {:?}", saved_user);
73
74    // Find user (find_by_id already uses transaction internally)
75    let found_user = user_model.find_by_id(&user_id, vec![]).await?;
76    println!("Found user: {:?}", found_user);
77
78    // Update user
79    let updated_user = User {
80        id: user_id.clone(),
81        name: "John Updated".to_string(),
82        email: "john_updated@example.com".to_string(),
83    };
84
85    tito_db
86        .transaction(|tx| {
87            let user_model = user_model.clone();
88            async move { user_model.update(updated_user, &tx).await }
89        })
90        .await?;
91
92    println!("User updated successfully");
93
94    // Delete user
95    tito_db
96        .transaction(|tx| {
97            let user_model = user_model.clone();
98            async move { user_model.delete_by_id(&user_id, &tx).await }
99        })
100        .await?;
101
102    println!("User deleted successfully");
103
104    Ok(())
105}
More examples
Hide additional examples
examples/blog.rs (line 278)
123async fn main() -> Result<(), TitoError> {
124    // Connect to TiKV
125    let tito_db = TiKV::connect(vec!["127.0.0.1:2379"]).await?;
126
127    // Create models
128    let post_model = tito_db.clone().model::<Post>();
129    let tag_model = tito_db.clone().model::<Tag>();
130
131    // Create some tags
132    let tech_tag = tito_db
133        .transaction(|tx| {
134            let tag_model = tag_model.clone();
135            let tag = Tag {
136                id: DBUuid::new_v4().to_string(),
137                name: "Technology".to_string(),
138                description: "All about tech".to_string(),
139            };
140            let tag_clone = tag.clone();
141
142            async move {
143                tag_model.build(tag_clone, &tx).await?;
144                Ok::<_, TitoError>(tag)
145            }
146        })
147        .await?;
148
149    let travel_tag = tito_db
150        .transaction(|tx| {
151            let tag_model = tag_model.clone();
152            let tag = Tag {
153                id: DBUuid::new_v4().to_string(),
154                name: "Travel".to_string(),
155                description: "Adventures around the world".to_string(),
156            };
157            let tag_clone = tag.clone();
158
159            async move {
160                tag_model.build(tag_clone, &tx).await?;
161                Ok::<_, TitoError>(tag)
162            }
163        })
164        .await?;
165
166    let rust_tag = tito_db
167        .transaction(|tx| {
168            let tag_model = tag_model.clone();
169            let tag = Tag {
170                id: DBUuid::new_v4().to_string(),
171                name: "Rust".to_string(),
172                description: "Rust programming language".to_string(),
173            };
174            let tag_clone = tag.clone();
175
176            async move {
177                tag_model.build(tag_clone, &tx).await?;
178                Ok::<_, TitoError>(tag)
179            }
180        })
181        .await?;
182
183    let database_tag = tito_db
184        .transaction(|tx| {
185            let tag_model = tag_model.clone();
186            let tag = Tag {
187                id: DBUuid::new_v4().to_string(),
188                name: "Databases".to_string(),
189                description: "Database systems and technologies".to_string(),
190            };
191            let tag_clone = tag.clone();
192
193            async move {
194                tag_model.build(tag_clone, &tx).await?;
195                Ok::<_, TitoError>(tag)
196            }
197        })
198        .await?;
199
200    println!("Created tags:");
201    println!("- {}: {}", tech_tag.name, tech_tag.id);
202    println!("- {}: {}", travel_tag.name, travel_tag.id);
203    println!("- {}: {}", rust_tag.name, rust_tag.id);
204    println!("- {}: {}", database_tag.name, database_tag.id);
205
206    // Create some posts with multiple tags
207    let post1 = tito_db
208        .transaction(|tx| {
209            let post_model = post_model.clone();
210            let post = Post {
211                id: DBUuid::new_v4().to_string(),
212                title: "Introduction to TiKV".to_string(),
213                content: "TiKV is a distributed key-value storage system...".to_string(),
214                author: "Alice".to_string(),
215                tag_ids: vec![tech_tag.id.clone(), database_tag.id.clone()],
216                tags: Vec::new(),
217            };
218            let post_clone = post.clone();
219
220            async move {
221                post_model.build(post_clone, &tx).await?;
222                Ok::<_, TitoError>(post)
223            }
224        })
225        .await?;
226
227    let post2 = tito_db
228        .transaction(|tx| {
229            let post_model = post_model.clone();
230            let post = Post {
231                id: DBUuid::new_v4().to_string(),
232                title: "Best cities to visit in Europe".to_string(),
233                content: "Europe offers a diverse range of cities...".to_string(),
234                author: "Bob".to_string(),
235                tag_ids: vec![travel_tag.id.clone()],
236                tags: Vec::new(),
237            };
238            let post_clone = post.clone();
239
240            async move {
241                post_model.build(post_clone, &tx).await?;
242                Ok::<_, TitoError>(post)
243            }
244        })
245        .await?;
246
247    let post3 = tito_db
248        .transaction(|tx| {
249            let post_model = post_model.clone();
250            let post = Post {
251                id: DBUuid::new_v4().to_string(),
252                title: "Using Rust with TiKV".to_string(),
253                content: "Here are some examples of using Rust with TiKV...".to_string(),
254                author: "Alice".to_string(),
255                tag_ids: vec![
256                    tech_tag.id.clone(),
257                    rust_tag.id.clone(),
258                    database_tag.id.clone(),
259                ],
260                tags: Vec::new(),
261            };
262            let post_clone = post.clone();
263
264            async move {
265                post_model.build(post_clone, &tx).await?;
266                Ok::<_, TitoError>(post)
267            }
268        })
269        .await?;
270
271    println!("\nCreated posts:");
272    println!("1. {} (by {})", post1.title, post1.author);
273    println!("2. {} (by {})", post2.title, post2.author);
274    println!("3. {} (by {})", post3.title, post3.author);
275
276    // Get a post with all its tags
277    let post_with_tags = post_model
278        .find_by_id(&post1.id, vec!["tags".to_string()])
279        .await?;
280    println!("\nPost with tags:");
281    println!("Title: {}", post_with_tags.title);
282    println!("Tags:");
283    for tag in &post_with_tags.tags {
284        println!("- {}", tag.name);
285    }
286
287    // Find posts by tag using the query builder
288    let mut tech_query = post_model.query_by_index("post-by-tag");
289    let tech_results = tech_query
290        .value(tech_tag.id.clone())
291        .relationship("tags")
292        .execute()
293        .await?;
294
295    println!("\nTechnology posts:");
296    for post in &tech_results.items {
297        println!("- {} (by {})", post.title, post.author);
298        println!(
299            "  Tags: {}",
300            post.tags
301                .iter()
302                .map(|t| t.name.clone())
303                .collect::<Vec<_>>()
304                .join(", ")
305        );
306    }
307
308    // Find posts by author using the query builder
309    let mut alice_query = post_model.query_by_index("post-by-author");
310    let alice_results = alice_query
311        .value("Alice".to_string())
312        .relationship("tags")
313        .execute()
314        .await?;
315
316    println!("\nAlice's posts:");
317    for post in &alice_results.items {
318        println!("- {}", post.title);
319        println!(
320            "  Tags: {}",
321            post.tags
322                .iter()
323                .map(|t| t.name.clone())
324                .collect::<Vec<_>>()
325                .join(", ")
326        );
327    }
328
329    Ok(())
330}
Source

pub async fn scan( &self, payload: TitoScanPayload, tx: &E::Transaction, ) -> Result<(Vec<(String, Value)>, bool), TitoError>

Source

pub async fn find_by_ids_tx( &self, ids: Vec<String>, rels: Vec<String>, tx: &E::Transaction, ) -> Result<Vec<T>, TitoError>

Source

pub async fn find_by_ids_raw( &self, ids: Vec<String>, rels: Vec<String>, tx: &E::Transaction, ) -> Result<Vec<(String, Value)>, TitoError>

Source

pub async fn find_by_ids( &self, ids: Vec<String>, rels: Vec<String>, ) -> Result<Vec<T>, TitoError>

Source

pub async fn scan_reverse( &self, payload: TitoScanPayload, tx: &E::Transaction, ) -> Result<(Vec<(String, Value)>, bool), TitoError>

Source

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

Examples found in repository?
examples/crud.rs (line 88)
49async fn main() -> Result<(), TitoError> {
50    // Connect to TiKV
51    let tito_db = TiKV::connect(vec!["127.0.0.1:2379"]).await?;
52
53    // Create model with dynamic backend
54    let user_model = tito_db.clone().model::<User>();
55
56    // Create a user
57    let user_id = DBUuid::new_v4().to_string();
58    let user = User {
59        id: user_id.clone(),
60        name: "John Doe".to_string(),
61        email: "john@example.com".to_string(),
62    };
63
64    // Create user with transaction
65    let saved_user = tito_db
66        .transaction(|tx| {
67            let user_model = user_model.clone();
68            async move { user_model.build(user, &tx).await }
69        })
70        .await?;
71
72    println!("Created user: {:?}", saved_user);
73
74    // Find user (find_by_id already uses transaction internally)
75    let found_user = user_model.find_by_id(&user_id, vec![]).await?;
76    println!("Found user: {:?}", found_user);
77
78    // Update user
79    let updated_user = User {
80        id: user_id.clone(),
81        name: "John Updated".to_string(),
82        email: "john_updated@example.com".to_string(),
83    };
84
85    tito_db
86        .transaction(|tx| {
87            let user_model = user_model.clone();
88            async move { user_model.update(updated_user, &tx).await }
89        })
90        .await?;
91
92    println!("User updated successfully");
93
94    // Delete user
95    tito_db
96        .transaction(|tx| {
97            let user_model = user_model.clone();
98            async move { user_model.delete_by_id(&user_id, &tx).await }
99        })
100        .await?;
101
102    println!("User deleted successfully");
103
104    Ok(())
105}
Source

pub fn get_last_id(&self, key: String) -> Option<String>

Source

pub async fn update_with_options( &self, payload: T, options: TitoOptions, tx: &E::Transaction, ) -> Result<bool, TitoError>

Source

pub async fn lock_keys( &self, keys: Vec<String>, tx: &E::Transaction, ) -> Result<bool, TitoError>

Source

pub async fn batch_get( &self, keys: Vec<String>, max_retries: usize, initial_delay_ms: u64, tx: &E::Transaction, ) -> Result<Vec<(String, Value)>, TitoError>

Source

pub async fn delete_by_id_with_options( &self, raw_id: &str, options: TitoOptions, tx: &E::Transaction, ) -> Result<bool, TitoError>

Source

pub async fn delete_by_id( &self, raw_id: &str, tx: &E::Transaction, ) -> Result<bool, TitoError>

Examples found in repository?
examples/crud.rs (line 98)
49async fn main() -> Result<(), TitoError> {
50    // Connect to TiKV
51    let tito_db = TiKV::connect(vec!["127.0.0.1:2379"]).await?;
52
53    // Create model with dynamic backend
54    let user_model = tito_db.clone().model::<User>();
55
56    // Create a user
57    let user_id = DBUuid::new_v4().to_string();
58    let user = User {
59        id: user_id.clone(),
60        name: "John Doe".to_string(),
61        email: "john@example.com".to_string(),
62    };
63
64    // Create user with transaction
65    let saved_user = tito_db
66        .transaction(|tx| {
67            let user_model = user_model.clone();
68            async move { user_model.build(user, &tx).await }
69        })
70        .await?;
71
72    println!("Created user: {:?}", saved_user);
73
74    // Find user (find_by_id already uses transaction internally)
75    let found_user = user_model.find_by_id(&user_id, vec![]).await?;
76    println!("Found user: {:?}", found_user);
77
78    // Update user
79    let updated_user = User {
80        id: user_id.clone(),
81        name: "John Updated".to_string(),
82        email: "john_updated@example.com".to_string(),
83    };
84
85    tito_db
86        .transaction(|tx| {
87            let user_model = user_model.clone();
88            async move { user_model.update(updated_user, &tx).await }
89        })
90        .await?;
91
92    println!("User updated successfully");
93
94    // Delete user
95    tito_db
96        .transaction(|tx| {
97            let user_model = user_model.clone();
98            async move { user_model.delete_by_id(&user_id, &tx).await }
99        })
100        .await?;
101
102    println!("User deleted successfully");
103
104    Ok(())
105}
Source

pub async fn find( &self, payload: TitoFindPayload, ) -> Result<TitoPaginated<T>, TitoError>

Source

pub async fn add_field( &self, field_name: &str, field_value: Value, ) -> Result<(), TitoError>

Source

pub async fn remove_field(&self, field_name: &str) -> Result<(), TitoError>

Source

pub async fn find_all(&self) -> Result<TitoPaginated<T>, TitoError>

Source§

impl<E: TitoEngine, T: Default + Clone + Serialize + DeserializeOwned + Unpin + Send + Sync + TitoModelTrait> TitoModel<E, T>

Source

pub fn get_index_keys( &self, id: String, value: &T, json: &Value, ) -> Result<Vec<(String, Value)>, TitoError>

Source

pub async fn find_by_index_raw( &self, payload: TitoFindByIndexPayload, tx: &E::Transaction, ) -> Result<(Vec<(String, Value)>, bool), TitoError>

Source

pub async fn find_by_index_reverse_raw( &self, payload: TitoFindByIndexPayload, tx: &E::Transaction, ) -> Result<(Vec<(String, Value)>, bool), TitoError>

Source

pub async fn find_by_index_tx( &self, payload: TitoFindByIndexPayload, tx: &E::Transaction, ) -> Result<TitoPaginated<T>, TitoError>

Source

pub async fn find_by_index( &self, payload: TitoFindByIndexPayload, ) -> Result<TitoPaginated<T>, TitoError>

Source

pub async fn find_by_index_reverse_tx( &self, payload: TitoFindByIndexPayload, tx: &E::Transaction, ) -> Result<TitoPaginated<T>, TitoError>

Source

pub async fn find_by_index_reverse( &self, payload: TitoFindByIndexPayload, ) -> Result<TitoPaginated<T>, TitoError>

Source

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

Source

pub async fn find_one_by_index( &self, payload: TitoFindOneByIndexPayload, ) -> Result<T, TitoError>

Source

pub async fn reindex(&self) -> Result<(), TitoError>

Source§

impl<E: TitoEngine, T: Default + Clone + Serialize + DeserializeOwned + Unpin + Send + Sync + TitoModelTrait> TitoModel<E, T>

Source

pub fn stitch_relationship( &self, item: &mut Value, rel_map: &HashMap<String, Value>, config: &TitoEmbeddedRelationshipConfig, )

Public entry point for stitching a relationship into a JSON Value.

Source

pub fn get_relationship_data( &self, items: &Vec<(String, Value)>, rels_config: &[TitoEmbeddedRelationshipConfig], rels: &Vec<String>, ) -> Vec<(TitoEmbeddedRelationshipConfig, String)>

Gathers all relationship keys that need to be fetched from a list of items.

Source

pub async fn fetch_and_stitch_relationships( &self, items: Vec<(String, Value)>, rels: Vec<String>, tx: &E::Transaction, ) -> Result<Vec<(String, Value)>, TitoError>

Fetches and stitches all requested relationships for a vector of items.

Source

pub fn extract_relationship(&self, input: &str) -> Option<String>

A helper function to extract a relationship string.

Trait Implementations§

Source§

impl<E: Clone + TitoEngine, T: Clone> Clone for TitoModel<E, T>

Source§

fn clone(&self) -> TitoModel<E, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<E, T> Freeze for TitoModel<E, T>
where T: Freeze, E: Freeze,

§

impl<E, T> RefUnwindSafe for TitoModel<E, T>

§

impl<E, T> Send for TitoModel<E, T>
where T: Send,

§

impl<E, T> Sync for TitoModel<E, T>
where T: Sync,

§

impl<E, T> Unpin for TitoModel<E, T>
where T: Unpin, E: Unpin,

§

impl<E, T> UnwindSafe for TitoModel<E, T>
where T: UnwindSafe, E: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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,