drizzle_mysql/result.rs
1//! Driver-independent results for MySQL mutation statements.
2
3/// The normalized result of executing a MySQL `INSERT`, `UPDATE`, or
4/// `DELETE` statement.
5///
6/// Concrete adapters translate their client's OK packet into this value so
7/// application code never depends on `mysql` or `mysql_async` result types.
8#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
9pub struct MySQLMutationResult {
10 affected_rows: u64,
11 last_insert_id: Option<u64>,
12}
13
14impl MySQLMutationResult {
15 /// Creates a normalized mutation result.
16 #[must_use]
17 pub const fn new(affected_rows: u64, last_insert_id: Option<u64>) -> Self {
18 Self {
19 affected_rows,
20 last_insert_id,
21 }
22 }
23
24 /// Number of rows affected according to MySQL's OK packet.
25 #[must_use]
26 pub const fn affected_rows(self) -> u64 {
27 self.affected_rows
28 }
29
30 /// First generated `AUTO_INCREMENT` value, when the server reported one.
31 ///
32 /// This is execution metadata, not SQL `RETURNING`. It does not imply
33 /// that every inserted row received a contiguous generated identifier.
34 #[must_use]
35 pub const fn last_insert_id(self) -> Option<u64> {
36 self.last_insert_id
37 }
38}