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

Access the underlying row type of QueryResult #2265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 50 additions & 0 deletions src/executor/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,56 @@ impl QueryResult {
_ => unreachable!(),
}
}

/// Access the underlying `MySqlRow` if we use the MySQL backend.
#[cfg(feature = "sqlx-mysql")]
pub fn try_as_mysql_row(&self) -> Option<&sqlx::mysql::MySqlRow> {
match &self.row {
QueryResultRow::SqlxMySql(mysql_row) => Some(mysql_row),
#[allow(unreachable_patterns)]
_ => None,
}
}

/// Access the underlying `PgRow` if we use the Postgres backend.
#[cfg(feature = "sqlx-postgres")]
pub fn try_as_pg_row(&self) -> Option<&sqlx::postgres::PgRow> {
match &self.row {
QueryResultRow::SqlxPostgres(pg_row) => Some(pg_row),
#[allow(unreachable_patterns)]
_ => None,
}
}

/// Access the underlying `SqliteRow` if we use the SQLite backend.
#[cfg(feature = "sqlx-sqlite")]
pub fn try_as_sqlite_row(&self) -> Option<&sqlx::sqlite::SqliteRow> {
match &self.row {
QueryResultRow::SqlxSqlite(sqlite_row) => Some(sqlite_row),
#[allow(unreachable_patterns)]
_ => None,
}
}

/// Access the underlying `MockRow` if we use a mock.
#[cfg(feature = "mock")]
pub fn try_as_mock_row(&self) -> Option<&crate::MockRow> {
match &self.row {
QueryResultRow::Mock(mock_row) => Some(mock_row),
#[allow(unreachable_patterns)]
_ => None,
}
}

/// Access the underlying `ProxyRow` if we use a proxy.
#[cfg(feature = "proxy")]
pub fn try_as_proxy_row(&self) -> Option<&crate::ProxyRow> {
match &self.row {
QueryResultRow::Proxy(proxy_row) => Some(proxy_row),
#[allow(unreachable_patterns)]
_ => None,
}
}
}

#[allow(unused_variables)]
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,6 @@ pub use sea_query::Iden;

pub use sea_orm_macros::EnumIter;
pub use strum;

#[cfg(feature = "sqlx-dep")]
pub use sqlx;
Loading