Skip to content

Commit

Permalink
Enable sqlite returning with feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
acrrd committed Jan 19, 2024
1 parent 131f9f1 commit f1fcb64
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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" }
# sea-query = { path = "../sea-query" }
1 change: 1 addition & 0 deletions sea-orm-migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
10 changes: 9 additions & 1 deletion src/database/db_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions tests/crud/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
8 changes: 7 additions & 1 deletion tests/returning_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit f1fcb64

Please sign in to comment.