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 fn get_last_insert_id(&self) -> i64 {
32 self.last_insert_id().unwrap_or(0)
33 }
34}
35
36#[cfg(feature = "strict-postgres")]
37impl QueryResultExt for sqlx::postgres::PgQueryResult {
38 fn get_last_insert_id(&self) -> i64 {
39 0
40 }
41}
42
43#[cfg(all(feature = "strict-mysql", not(feature = "strict-postgres")))]
44impl QueryResultExt for sqlx::mysql::MySqlQueryResult {
45 fn get_last_insert_id(&self) -> i64 {
46 self.last_insert_id() as i64
47 }
48}
49
50#[cfg(all(
51 feature = "strict-sqlite",
52 not(feature = "strict-postgres"),
53 not(feature = "strict-mysql")
54))]
55impl QueryResultExt for sqlx::sqlite::SqliteQueryResult {
56 fn get_last_insert_id(&self) -> i64 {
57 self.last_insert_rowid()
58 }
59}