Skip to main content

rullst_orm/
database.rs

1#[cfg(not(any(feature = "strict-postgres", feature = "strict-mysql", feature = "strict-sqlite")))]
2pub type EloquentDatabase = sqlx::Any;
3
4#[cfg(feature = "strict-postgres")]
5pub type EloquentDatabase = sqlx::Postgres;
6
7#[cfg(all(feature = "strict-mysql", not(feature = "strict-postgres")))]
8pub type EloquentDatabase = sqlx::MySql;
9
10#[cfg(all(feature = "strict-sqlite", not(feature = "strict-postgres"), not(feature = "strict-mysql")))]
11pub type EloquentDatabase = sqlx::Sqlite;
12
13pub trait QueryResultExt {
14    fn get_last_insert_id(&self) -> i64;
15}
16
17#[cfg(not(any(feature = "strict-postgres", feature = "strict-mysql", feature = "strict-sqlite")))]
18impl QueryResultExt for sqlx::any::AnyQueryResult {
19    fn get_last_insert_id(&self) -> i64 {
20        self.last_insert_id().unwrap_or(0)
21    }
22}
23
24#[cfg(feature = "strict-postgres")]
25impl QueryResultExt for sqlx::postgres::PgQueryResult {
26    fn get_last_insert_id(&self) -> i64 {
27        0
28    }
29}
30
31#[cfg(all(feature = "strict-mysql", not(feature = "strict-postgres")))]
32impl QueryResultExt for sqlx::mysql::MySqlQueryResult {
33    fn get_last_insert_id(&self) -> i64 {
34        self.last_insert_id() as i64
35    }
36}
37
38#[cfg(all(feature = "strict-sqlite", not(feature = "strict-postgres"), not(feature = "strict-mysql")))]
39impl QueryResultExt for sqlx::sqlite::SqliteQueryResult {
40    fn get_last_insert_id(&self) -> i64 {
41        self.last_insert_rowid()
42    }
43}