MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / last_insert_id

Method last_insert_id

src/executor/execute.rs:38–62  ·  view source on GitHub ↗

Get the last id after `AUTOINCREMENT` is done on the primary key # Panics Postgres does not support retrieving last insert id this way except through `RETURNING` clause

(&self)

Source from the content-addressed store, hash-verified

36 ///
37 /// Postgres does not support retrieving last insert id this way except through `RETURNING` clause
38 pub fn last_insert_id(&self) -> u64 {
39 match &self.result {
40 #[cfg(feature = "sqlx-mysql")]
41 ExecResultHolder::SqlxMySql(result) => result.last_insert_id(),
42 #[cfg(feature = "sqlx-postgres")]
43 ExecResultHolder::SqlxPostgres(_) => {
44 panic!("Should not retrieve last_insert_id this way")
45 }
46 #[cfg(feature = "sqlx-sqlite")]
47 ExecResultHolder::SqlxSqlite(result) => {
48 let last_insert_rowid = result.last_insert_rowid();
49 if last_insert_rowid < 0 {
50 unreachable!("negative last_insert_rowid")
51 } else {
52 last_insert_rowid as u64
53 }
54 }
55 #[cfg(feature = "mock")]
56 ExecResultHolder::Mock(result) => result.last_insert_id,
57 #[cfg(feature = "proxy")]
58 ExecResultHolder::Proxy(result) => result.last_insert_id,
59 #[allow(unreachable_patterns)]
60 _ => unreachable!(),
61 }
62 }
63
64 /// Get the number of rows affected by the operation
65 pub fn rows_affected(&self) -> u64 {

Callers 2

fromMethod · 0.80
exec_insertFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected