Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning #292

Merged
merged 33 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c5468eb
Use "marlon-sousa/sea-query"
billy1624 Nov 5, 2021
c39a3b8
Insert with returning for Postgres
billy1624 Nov 5, 2021
52ff943
Docs
billy1624 Nov 5, 2021
a977572
Update with returning for Postgres
billy1624 Nov 5, 2021
50605c7
FIXME: breaking behaviors
billy1624 Nov 5, 2021
6238736
Handle "None of the database rows are affected" for Postgres
billy1624 Nov 8, 2021
2f7cffa
Fix test cases
billy1624 Nov 8, 2021
732d080
Update docs
billy1624 Nov 8, 2021
0eafacc
Try returning on MariaDB
billy1624 Nov 8, 2021
80c0d69
Merge remote-tracking branch 'origin/master' into returning
billy1624 Nov 8, 2021
30f43b6
Fixup
billy1624 Nov 8, 2021
2f0ac4c
Fixup
billy1624 Nov 8, 2021
afdb1af
This will fail loll
billy1624 Nov 8, 2021
1723206
This will fail loll
billy1624 Nov 8, 2021
3e6423a
This will fail loll
billy1624 Nov 8, 2021
30a50ca
Try
billy1624 Nov 9, 2021
429b920
Fixup
billy1624 Nov 9, 2021
24fab66
Try
billy1624 Nov 9, 2021
8020ae1
Fixup
billy1624 Nov 9, 2021
533c3cf
Try
billy1624 Nov 9, 2021
ec637b2
Returning support for SQLite
billy1624 Nov 9, 2021
c1fae1b
Debug print
billy1624 Nov 9, 2021
cc035d7
Refactoring
billy1624 Nov 9, 2021
66c23c8
Revert MySQL & SQLite returning support
billy1624 Nov 10, 2021
257a893
Use `sea-query` master
billy1624 Nov 10, 2021
4d44827
Docs
billy1624 Nov 11, 2021
fd50ffd
Merge remote-tracking branch 'origin/master' into returning
billy1624 Nov 16, 2021
d5de8b1
Should fail
billy1624 Nov 16, 2021
9655805
Will fail, as expected
billy1624 Nov 16, 2021
4c147a2
Rewrite doctests
billy1624 Nov 16, 2021
f9d04fc
Hotfix - separate counter for mock exec & query
billy1624 Nov 16, 2021
7298fde
Rewrite doctests
billy1624 Nov 16, 2021
42404eb
Fixup
billy1624 Nov 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ jobs:
name: Examples
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
path: [basic, actix_example, actix4_example, axum_example, rocket_example]
Expand All @@ -312,6 +313,7 @@ jobs:
if: ${{ (needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-issues == 'true') }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
path: [86, 249, 262, 319]
Expand Down Expand Up @@ -350,6 +352,7 @@ jobs:
env:
DATABASE_URL: "sqlite::memory:"
strategy:
fail-fast: false
matrix:
runtime: [async-std, actix, tokio]
tls: [native-tls, rustls]
Expand Down Expand Up @@ -392,6 +395,7 @@ jobs:
env:
DATABASE_URL: "mysql://root:@localhost"
strategy:
fail-fast: false
matrix:
version: [8.0, 5.7]
runtime: [async-std, actix, tokio]
Expand Down Expand Up @@ -452,8 +456,9 @@ jobs:
env:
DATABASE_URL: "mysql://root:@localhost"
strategy:
fail-fast: false
matrix:
version: [10.6]
version: [10.6, 10.5, 10.4]
runtime: [async-std, actix, tokio]
tls: [native-tls]
services:
Expand Down Expand Up @@ -512,8 +517,9 @@ jobs:
env:
DATABASE_URL: "postgres://root:root@localhost"
strategy:
fail-fast: false
matrix:
version: [13.3, 12.7, 11.12, 10.17, 9.6.22]
version: [13, 12, 11, 10, 9]
runtime: [tokio]
tls: [native-tls]
services:
Expand Down
6 changes: 6 additions & 0 deletions src/database/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ pub trait ConnectionTrait<'a>: Sync {
T: Send,
E: std::error::Error + Send;

/// Check if the connection supports `RETURNING` syntax on insert and update
fn support_returning(&self) -> bool {
let db_backend = self.get_database_backend();
db_backend.support_returning()
}

/// Check if the connection is a test connection for the Mock database
fn is_mock_connection(&self) -> bool {
false
Expand Down
5 changes: 5 additions & 0 deletions src/database/db_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ impl DbBackend {
Self::Sqlite => Box::new(SqliteQueryBuilder),
}
}

/// Check if the database supports `RETURNING` syntax on insert and update
pub fn support_returning(&self) -> bool {
matches!(self, Self::Postgres)
tyt2y3 marked this conversation as resolved.
Show resolved Hide resolved
}
}

#[cfg(test)]
Expand Down
11 changes: 8 additions & 3 deletions src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
//! Relying on [SQLx](https://github.com/launchbadge/sqlx), SeaORM is a new library with async support from day 1.
//!
//! ```
//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*, DatabaseConnection, DbBackend, MockDatabase, Transaction, IntoMockRow};
//! # use sea_orm::{error::*, tests_cfg::*, *};
//! #
//! # #[smol_potat::main]
//! # #[cfg(feature = "mock")]
//! # pub async fn main() -> Result<(), DbErr> {
//! #
//! # let db = MockDatabase::new(DbBackend::Postgres)
//! # .append_query_results(vec![
//! # vec![cake::Model {
Expand All @@ -19,7 +24,7 @@
//! # .into_mock_row()],
//! # ])
//! # .into_connection();
//! # let _: Result<(), DbErr> = smol::block_on(async {
//! #
//! // execute multiple queries in parallel
//! let cakes_and_fruits: (Vec<cake::Model>, Vec<fruit::Model>) =
//! futures::try_join!(Cake::find().all(&db), Fruit::find().all(&db))?;
Expand Down Expand Up @@ -53,7 +58,7 @@
//! # ]
//! # );
//! # Ok(())
//! # });
//! # }
//! ```
//!
//! 2. Dynamic
Expand Down
12 changes: 7 additions & 5 deletions src/driver/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub struct MockDatabaseConnector;
/// Defines a connection for the [MockDatabase]
#[derive(Debug)]
pub struct MockDatabaseConnection {
counter: AtomicUsize,
execute_counter: AtomicUsize,
query_counter: AtomicUsize,
mocker: Mutex<Box<dyn MockDatabaseTrait>>,
}

Expand Down Expand Up @@ -100,7 +101,8 @@ impl MockDatabaseConnection {
M: MockDatabaseTrait,
{
Self {
counter: AtomicUsize::new(0),
execute_counter: AtomicUsize::new(0),
query_counter: AtomicUsize::new(0),
mocker: Mutex::new(Box::new(m)),
}
}
Expand All @@ -117,22 +119,22 @@ impl MockDatabaseConnection {
/// Execute the SQL statement in the [MockDatabase]
pub fn execute(&self, statement: Statement) -> Result<ExecResult, DbErr> {
debug_print!("{}", statement);
let counter = self.counter.fetch_add(1, Ordering::SeqCst);
let counter = self.execute_counter.fetch_add(1, Ordering::SeqCst);
self.mocker.lock().unwrap().execute(counter, statement)
}

/// Return one [QueryResult] if the query was successful
pub fn query_one(&self, statement: Statement) -> Result<Option<QueryResult>, DbErr> {
debug_print!("{}", statement);
let counter = self.counter.fetch_add(1, Ordering::SeqCst);
let counter = self.query_counter.fetch_add(1, Ordering::SeqCst);
let result = self.mocker.lock().unwrap().query(counter, statement)?;
Ok(result.into_iter().next())
}

/// Return all [QueryResult]s if the query was successful
pub fn query_all(&self, statement: Statement) -> Result<Vec<QueryResult>, DbErr> {
debug_print!("{}", statement);
let counter = self.counter.fetch_add(1, Ordering::SeqCst);
let counter = self.query_counter.fetch_add(1, Ordering::SeqCst);
self.mocker.lock().unwrap().query(counter, statement)
}

Expand Down
Loading