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

Improve working with raw SQL #167

Merged
merged 2 commits into from
Sep 17, 2021
Merged

Improve working with raw SQL #167

merged 2 commits into from
Sep 17, 2021

Conversation

MuhannadAlrusayni
Copy link
Contributor

@MuhannadAlrusayni MuhannadAlrusayni commented Sep 16, 2021

(updated) This PR allow us to fetch T: FromQueryResult using T::find_by_statement() from raw sql:

// with this PR we can call `T::find_by_statement()` where `T: FromQueryResult` and return `T`
let res: Vec<SelectResult> = SelectResult::find_by_statement(Statement::from_sql_and_values(
    DbBackend::Postgres,
    r#"SELECT "cake"."name", count("cake"."id") AS "num_of_cakes" FROM "cake""#,
    vec![],
))
.all(&db)
.await?;

src/database/statement.rs Outdated Show resolved Hide resolved
src/executor/select.rs Outdated Show resolved Hide resolved
- Add `find_by_statement` to `T: FromQueryResult`
- Add `SelectorRaw::from_statement` constructor
@MuhannadAlrusayni MuhannadAlrusayni changed the title add into_model() for Statement Improve working with raw SQL Sep 16, 2021
@tyt2y3 tyt2y3 merged commit 94b5fbf into SeaQL:master Sep 17, 2021
@billy1624 billy1624 mentioned this pull request Sep 17, 2021
11 tasks
@tyt2y3
Copy link
Member

tyt2y3 commented Sep 17, 2021

@MuhannadAlrusayni thank you for the contribution.

On a second look I found that Sized is already a requirement of FromQueryResult, so I merged the method back into FromQueryResult.

billy1624 added a commit to SeaQL/seaql.github.io that referenced this pull request Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants