1#[cfg(not(any(
2 feature = "strict-postgres",
3 feature = "strict-mysql",
4 feature = "strict-sqlite"
5)))]
6pub type RullstDatabase = sqlx::Any;
7
8#[cfg(feature = "strict-postgres")]
9pub type RullstDatabase = sqlx::Postgres;
10
11#[cfg(all(feature = "strict-mysql", not(feature = "strict-postgres")))]
12pub type RullstDatabase = sqlx::MySql;
13
14#[cfg(all(
15 feature = "strict-sqlite",
16 not(feature = "strict-postgres"),
17 not(feature = "strict-mysql")
18))]
19pub type RullstDatabase = sqlx::Sqlite;
20
21pub trait QueryResultExt {
22 fn get_last_insert_id(&self) -> i64;
23}
24
25#[cfg(not(any(
26 feature = "strict-postgres",
27 feature = "strict-mysql",
28 feature = "strict-sqlite"
29)))]
30impl QueryResultExt for sqlx::any::AnyQueryResult {
31 #[cfg_attr(test, mutants::skip)]
32 fn get_last_insert_id(&self) -> i64 {
33 self.last_insert_id().unwrap_or(0)
34 }
35}
36
37#[cfg(feature = "strict-postgres")]
38impl QueryResultExt for sqlx::postgres::PgQueryResult {
39 #[cfg_attr(test, mutants::skip)]
40 fn get_last_insert_id(&self) -> i64 {
41 0
42 }
43}
44
45#[cfg(all(feature = "strict-mysql", not(feature = "strict-postgres")))]
46impl QueryResultExt for sqlx::mysql::MySqlQueryResult {
47 #[cfg_attr(test, mutants::skip)]
48 fn get_last_insert_id(&self) -> i64 {
49 self.last_insert_id() as i64
50 }
51}
52
53#[cfg(all(
54 feature = "strict-sqlite",
55 not(feature = "strict-postgres"),
56 not(feature = "strict-mysql")
57))]
58impl QueryResultExt for sqlx::sqlite::SqliteQueryResult {
59 #[cfg_attr(test, mutants::skip)]
60 fn get_last_insert_id(&self) -> i64 {
61 self.last_insert_rowid()
62 }
63}