diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 73ba4ce7e9..a655af37b1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -308,6 +308,7 @@ jobs: matrix: runtime: [async-std] tls: [native-tls, rustls] + sqlite_flavor: ["", returning_clauses_for_sqlite_3_35] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable @@ -319,8 +320,8 @@ jobs: Cargo.lock target key: ${{ github.sha }}-${{ github.run_id }}-${{ runner.os }}-sqlite-${{ matrix.runtime }}-${{ matrix.tls }} - - run: cargo test --test '*' --features default,sqlx-sqlite,runtime-${{ matrix.runtime }}-${{ matrix.tls }} - - run: cargo test --manifest-path sea-orm-migration/Cargo.toml --test '*' --features sqlx-sqlite,runtime-${{ matrix.runtime }}-${{ matrix.tls }} + - run: cargo test --test '*' --features default,sqlx-sqlite,runtime-${{ matrix.runtime }}-${{ matrix.tls }},${{ matrix.sqlite_flavor }} + - run: cargo test --manifest-path sea-orm-migration/Cargo.toml --test '*' --features sqlx-sqlite,runtime-${{ matrix.runtime }}-${{ matrix.tls }},${{ matrix.sqlite_flavor }} mysql: name: MySQL diff --git a/Cargo.toml b/Cargo.toml index 22676c2305..385e3341d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,6 +91,7 @@ sqlx-all = ["sqlx-mysql", "sqlx-postgres", "sqlx-sqlite"] sqlx-mysql = ["sqlx-dep", "sea-query-binder/sqlx-mysql", "sqlx/mysql"] sqlx-postgres = ["sqlx-dep", "sea-query-binder/sqlx-postgres", "sqlx/postgres", "postgres-array"] sqlx-sqlite = ["sqlx-dep", "sea-query-binder/sqlx-sqlite", "sqlx/sqlite"] +returning_clauses_for_sqlite_3_35 = [] runtime-async-std = [] runtime-async-std-native-tls = [ "sqlx?/runtime-async-std-native-tls", @@ -129,4 +130,4 @@ seaography = ["sea-orm-macros/seaography"] # This allows us to develop using a local version of sea-query # [patch.crates-io] -# sea-query = { path = "../sea-query" } \ No newline at end of file +# sea-query = { path = "../sea-query" } diff --git a/sea-orm-migration/Cargo.toml b/sea-orm-migration/Cargo.toml index ec9346ef70..c2961af30a 100644 --- a/sea-orm-migration/Cargo.toml +++ b/sea-orm-migration/Cargo.toml @@ -39,6 +39,7 @@ cli = ["clap", "dotenvy", "sea-orm-cli/cli"] sqlx-mysql = ["sea-orm/sqlx-mysql"] sqlx-postgres = ["sea-orm/sqlx-postgres"] sqlx-sqlite = ["sea-orm/sqlx-sqlite"] +returning_clauses_for_sqlite_3_35 = ["sea-orm/returning_clauses_for_sqlite_3_35"] runtime-actix-native-tls = ["sea-orm/runtime-actix-native-tls"] runtime-async-std-native-tls = ["sea-orm/runtime-async-std-native-tls"] runtime-tokio-native-tls = ["sea-orm/runtime-tokio-native-tls"] diff --git a/src/database/db_connection.rs b/src/database/db_connection.rs index 29815ec9f0..82aba983d7 100644 --- a/src/database/db_connection.rs +++ b/src/database/db_connection.rs @@ -578,7 +578,15 @@ impl DbBackend { /// Check if the database supports `RETURNING` syntax on insert and update pub fn support_returning(&self) -> bool { - matches!(self, Self::Postgres) + #[cfg(not(feature = "returning_clauses_for_sqlite_3_35"))] + { + matches!(self, Self::Postgres) + } + + #[cfg(feature = "returning_clauses_for_sqlite_3_35")] + { + matches!(self, Self::Postgres | Self::Sqlite) + } } } diff --git a/tests/crud/error.rs b/tests/crud/error.rs index 07bb510093..11bde22b67 100644 --- a/tests/crud/error.rs +++ b/tests/crud/error.rs @@ -41,6 +41,10 @@ pub async fn test_cake_error_sqlx(db: &DbConn) { } _ => panic!("Unexpected sqlx-error kind"), }, + #[cfg(all(feature = "sqlx-sqlite", feature = "returning_clauses_for_sqlite_3_35"))] + DbErr::Query(RuntimeErr::SqlxError(Error::Database(e))) => { + assert_eq!(e.code().unwrap(), "1555"); + }, _ => panic!("Unexpected Error kind"), } #[cfg(feature = "sqlx-postgres")] diff --git a/tests/returning_tests.rs b/tests/returning_tests.rs index 68abbf7750..94f5e9a409 100644 --- a/tests/returning_tests.rs +++ b/tests/returning_tests.rs @@ -75,7 +75,13 @@ async fn main() -> Result<(), DbErr> { feature = "sqlx-postgres" ))] #[cfg_attr( - any(feature = "sqlx-mysql", feature = "sqlx-sqlite"), + any( + feature = "sqlx-mysql", + all( + feature = "sqlx-sqlite", + not(feature = "returning_clauses_for_sqlite_3_35") + ) + ), should_panic(expected = "Database backend doesn't support RETURNING") )] async fn update_many() {