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