Skip to content

Commit f0a1d9f

Browse files
committed
Update docs
1 parent 82cfed3 commit f0a1d9f

File tree

5 files changed

+56
-31
lines changed

5 files changed

+56
-31
lines changed

src/conn/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl ConnInner {
146146
}
147147
}
148148

149+
/// MySql server connection.
149150
#[derive(Debug)]
150151
pub struct Conn {
151152
inner: Box<ConnInner>,

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
//! Payment { customer_id: 7, amount: 8, account_name: None },
4141
//! Payment { customer_id: 9, amount: 10, account_name: Some("bar".into()) },
4242
//! ];
43-
//! let payments_clone = payments.clone();
4443
//!
4544
//! let database_url = /* ... */
4645
//! # get_opts();
@@ -58,17 +57,17 @@
5857
//! ).await?;
5958
//!
6059
//! // Save payments
61-
//! let params = payments_clone.into_iter().map(|payment| {
60+
//! let params = payments.clone().into_iter().map(|payment| {
6261
//! params! {
6362
//! "customer_id" => payment.customer_id,
6463
//! "amount" => payment.amount,
65-
//! "account_name" => payment.account_name.clone(),
64+
//! "account_name" => payment.account_name,
6665
//! }
6766
//! });
6867
//!
6968
//! conn.exec_batch(
7069
//! r"INSERT INTO payment (customer_id, amount, account_name)
71-
//! VALUES (:customer_id, :amount, :account_name)",
70+
//! VALUES (:customer_id, :amount, :account_name)",
7271
//! params,
7372
//! ).await?;
7473
//!

src/queryable/mod.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ impl Conn {
101101
}
102102
}
103103

104+
/// Methods of this trait used to execute database queries.
104105
pub trait Queryable: Send {
105106
/// Executes `COM_PING`.
106107
fn ping(&mut self) -> BoxFuture<'_, ()>;
@@ -114,14 +115,23 @@ pub trait Queryable: Send {
114115
Q: AsRef<str> + Send + Sync + 'a;
115116

116117
/// Prepares the given statement.
118+
///
119+
/// Note, that `Statement` will exist only in the context of this queryable.
120+
///
121+
/// Also note, that this call may close the least recently used statement
122+
/// if statement cache is at its capacity (see. [`stmt_cache_size`]).
117123
fn prep<'a, Q>(&'a mut self, query: Q) -> BoxFuture<'a, Statement>
118124
where
119125
Q: AsRef<str> + Sync + Send + 'a;
120126

121127
/// Closes the given statement.
128+
///
129+
/// Usually there is no need to explicitly close statements (see. [`stmt_cache_size`]).
122130
fn close(&mut self, stmt: Statement) -> BoxFuture<'_, ()>;
123131

124132
/// Executes the given statement with the given params.
133+
///
134+
/// It'll prepare `stmt`, if necessary.
125135
fn exec_iter<'a: 's, 's, Q, P>(
126136
&'a mut self,
127137
stmt: &'s Q,
@@ -137,13 +147,13 @@ pub trait Queryable: Send {
137147
Q: AsRef<str> + Send + Sync + 'a,
138148
T: FromRow + Send + 'static;
139149

140-
/// Performs the given query and returns the firt row of the first result set.
150+
/// Performs the given query and returns the first row of the first result set.
141151
fn query_first<'a, T, Q>(&'a mut self, query: Q) -> BoxFuture<'a, Option<T>>
142152
where
143153
Q: AsRef<str> + Send + Sync + 'a,
144154
T: FromRow + Send + 'static;
145155

146-
/// Performs the given query and returns the firt row of the first result set.
156+
/// Performs the given query and returns the first row of the first result set.
147157
fn query_map<'a, T, F, Q, U>(&'a mut self, query: Q, f: F) -> BoxFuture<'a, Vec<U>>
148158
where
149159
Q: AsRef<str> + Send + Sync + 'a,
@@ -164,7 +174,9 @@ pub trait Queryable: Send {
164174
where
165175
Q: AsRef<str> + Send + Sync + 'a;
166176

167-
/// Prepares the given statement, and exectues it with each item in the given params iterator.
177+
/// Exectues the given statement with each item in the given params iterator.
178+
///
179+
/// It'll prepare `stmt`, if necessary.
168180
fn exec_batch<'a: 'b, 'b, S, P, I>(
169181
&'a mut self,
170182
stmt: &'b S,
@@ -177,13 +189,17 @@ pub trait Queryable: Send {
177189
P: Into<Params> + Send;
178190

179191
/// Exectues the given statement and collects the first result set.
192+
///
193+
/// It'll prepare `stmt`, if necessary.
180194
fn exec<'a: 'b, 'b, T, S, P>(&'a mut self, stmt: &'b S, params: P) -> BoxFuture<'b, Vec<T>>
181195
where
182196
S: StatementLike + ?Sized + 'b,
183197
P: Into<Params> + Send + 'b,
184198
T: FromRow + Send + 'static;
185199

186200
/// Exectues the given statement and returns the first row of the first result set.
201+
///
202+
/// It'll prepare `stmt`, if necessary.
187203
fn exec_first<'a: 'b, 'b, T, S, P>(
188204
&'a mut self,
189205
stmt: &'b S,
@@ -195,6 +211,8 @@ pub trait Queryable: Send {
195211
T: FromRow + Send + 'static;
196212

197213
/// Exectues the given stmt and folds the first result set to a signel value.
214+
///
215+
/// It'll prepare `stmt`, if necessary.
198216
fn exec_map<'a: 'b, 'b, T, S, P, U, F>(
199217
&'a mut self,
200218
stmt: &'b S,
@@ -209,6 +227,8 @@ pub trait Queryable: Send {
209227
U: Send + 'a;
210228

211229
/// Exectues the given stmt and folds the first result set to a signel value.
230+
///
231+
/// It'll prepare `stmt`, if necessary.
212232
fn exec_fold<'a: 'b, 'b, T, S, P, U, F>(
213233
&'a mut self,
214234
stmt: &'b S,

src/queryable/query_result.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ impl ResultSetMeta {
4040
}
4141

4242
/// Result of a query or statement execution.
43+
///
44+
/// Represents an asyncronous query result, that may not be fully consumed. Note,
45+
/// that unconsumed query results are dropped implicitly when corresponding connection
46+
/// is dropped or queried.
4347
#[derive(Debug)]
4448
pub struct QueryResult<'a, 't: 'a, P> {
4549
conn: Connection<'a, 't>,
@@ -59,17 +63,15 @@ where
5963

6064
/// Returns `true` if this query result may contain rows.
6165
///
62-
/// If `false` then there is no rows possible (e.g. result of an UPDATE query).
66+
/// If `false` then no rows possible for this query tesult (e.g. result of an UPDATE query).
6367
fn has_rows(&self) -> bool {
6468
self.conn
6569
.get_pending_result()
6670
.and_then(|meta| meta.columns().map(|columns| columns.len() > 0).ok())
6771
.unwrap_or(false)
6872
}
6973

70-
/// `true` if there is no more rows nor result sets in this query.
71-
///
72-
/// One could use it to check if there is more than one result set in this query result.
74+
/// `true` if there are no more rows nor result sets in this query.
7375
pub fn is_empty(&self) -> bool {
7476
!self.has_rows() && !self.conn.more_results_exists()
7577
}
@@ -137,22 +139,22 @@ where
137139
self.conn.last_insert_id()
138140
}
139141

140-
/// Number of affected rows, as reported by the server, or `0`.
142+
/// Number of affected rows as reported by the server, or `0`.
141143
pub fn affected_rows(&self) -> u64 {
142144
self.conn.affected_rows()
143145
}
144146

145-
/// Text information, as reported by the server, or an empty string.
147+
/// Text information as reported by the server, or an empty string.
146148
pub fn info(&self) -> Cow<'_, str> {
147149
self.conn.info()
148150
}
149151

150-
/// Number of warnings, as reported by the server, or `0`.
152+
/// Number of warnings as reported by the server, or `0`.
151153
pub fn warnings(&self) -> u16 {
152154
self.conn.get_warnings()
153155
}
154156

155-
/// Returns a future that collects result set of this query result.
157+
/// Collects the current result set of this query result.
156158
///
157159
/// It is parametrized by `R` and internally calls `R::from_row(Row)` on each row.
158160
///
@@ -177,7 +179,7 @@ where
177179
.await
178180
}
179181

180-
/// Returns a future that collects result set of this query result.
182+
/// Collects the current result set of this query result.
181183
///
182184
/// It works the same way as [`QueryResult::collect`] but won't panic if row isn't convertible
183185
/// to `R`.
@@ -192,8 +194,7 @@ where
192194
.await
193195
}
194196

195-
/// Returns a future that collects the current result set of this query result and drops
196-
/// everything else.
197+
/// Collects the current result set of this query result and drops everything else.
197198
///
198199
/// # Panic
199200
///
@@ -209,8 +210,7 @@ where
209210
Ok(output)
210211
}
211212

212-
/// Returns a future that collects the current result set of this query result and drops
213-
/// everything else.
213+
/// Collects the current result set of this query result and drops everything else.
214214
///
215215
/// It works the same way as [`QueryResult::collect_and_drop`] but won't panic if row isn't
216216
/// convertible to `R`.
@@ -223,7 +223,7 @@ where
223223
Ok(output)
224224
}
225225

226-
/// Returns a future that will execute `fun` on every row of the current result set.
226+
/// Executes `fun` on every row of the current result set.
227227
///
228228
/// It will stop on the nearest result set boundary (see `QueryResult::collect` docs).
229229
pub async fn for_each<F>(&mut self, mut fun: F) -> Result<()>
@@ -240,8 +240,7 @@ where
240240
}
241241
}
242242

243-
/// Returns a future that will execute `fun` on every row of the current result set and drop
244-
/// everything else.
243+
/// Executes `fun` on every row of the current result set and drops everything else.
245244
pub async fn for_each_and_drop<F>(mut self, fun: F) -> Result<()>
246245
where
247246
F: FnMut(Row),
@@ -251,7 +250,7 @@ where
251250
Ok(())
252251
}
253252

254-
/// Returns a future that will map every row of the current result set to `U` using `fun`.
253+
/// Maps every row of the current result set to `U` using `fun`.
255254
///
256255
/// It will stop on the nearest result set boundary (see `QueryResult::collect` docs).
257256
pub async fn map<F, U>(&mut self, mut fun: F) -> Result<Vec<U>>
@@ -265,8 +264,7 @@ where
265264
Ok(acc)
266265
}
267266

268-
/// Returns a future that will map every row of the current result set to `U` using `fun`
269-
/// and drop everything else.
267+
/// Map every row of the current result set to `U` using `fun` and drops everything else.
270268
pub async fn map_and_drop<F, U>(mut self, fun: F) -> Result<Vec<U>>
271269
where
272270
F: FnMut(Row) -> U,
@@ -276,7 +274,7 @@ where
276274
Ok(rows)
277275
}
278276

279-
/// Returns a future that will reduce rows of the current result set to `U` using `fun`.
277+
/// Reduces rows of the current result set to `U` using `fun`.
280278
///
281279
/// It will stop on the nearest result set boundary (see `QueryResult::collect` docs).
282280
pub async fn reduce<T, F, U>(&mut self, mut init: U, mut fun: F) -> Result<U>
@@ -290,8 +288,7 @@ where
290288
Ok(init)
291289
}
292290

293-
/// Returns a future that will reduce rows of the current result set to `U` using `fun` and drop
294-
/// everything else.
291+
/// Reduces rows of the current result set to `U` using `fun` and drops everything else.
295292
pub async fn reduce_and_drop<T, F, U>(mut self, init: U, fun: F) -> Result<U>
296293
where
297294
F: FnMut(U, T) -> U,
@@ -302,7 +299,7 @@ where
302299
Ok(acc)
303300
}
304301

305-
/// Returns a future that will drop this query result.
302+
/// Drops this query result.
306303
pub async fn drop_result(mut self) -> Result<()> {
307304
loop {
308305
while let Some(_) = self.next().await? {}
@@ -314,7 +311,7 @@ where
314311

315312
/// Returns a reference to a columns list of this query result.
316313
///
317-
/// Empty list means, that this result set was never meant to contain rows.
314+
/// Empty list means that this result set was never meant to contain rows.
318315
pub fn columns_ref(&self) -> &[Column] {
319316
self.conn
320317
.get_pending_result()

src/queryable/stmt.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ impl StmtInner {
125125
}
126126

127127
/// Prepared statement.
128+
///
129+
/// Statement is only valid for connection with id `Statement::connection_id()`.
128130
#[derive(Debug, Clone, Eq, PartialEq)]
129131
pub struct Statement {
130132
pub(crate) inner: Arc<StmtInner>,
@@ -139,26 +141,32 @@ impl Statement {
139141
}
140142
}
141143

144+
/// Returned columns.
142145
pub fn columns(&self) -> &[Column] {
143146
self.inner.columns()
144147
}
145148

149+
/// Requred parameters.
146150
pub fn params(&self) -> &[Column] {
147151
self.inner.params()
148152
}
149153

154+
/// MySql statement identifier.
150155
pub fn id(&self) -> u32 {
151156
self.inner.id()
152157
}
153158

159+
/// MySql connection identifier.
154160
pub fn connection_id(&self) -> u32 {
155161
self.inner.connection_id()
156162
}
157163

164+
/// Number of parameters.
158165
pub fn num_params(&self) -> u16 {
159166
self.inner.num_params()
160167
}
161168

169+
/// Number of columns.
162170
pub fn num_columns(&self) -> u16 {
163171
self.inner.num_columns()
164172
}

0 commit comments

Comments
 (0)