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

Add support for raw subqueries #44

Open
ellmetha opened this issue Nov 11, 2022 · 0 comments
Open

Add support for raw subqueries #44

ellmetha opened this issue Nov 11, 2022 · 0 comments
Assignees
Milestone

Comments

@ellmetha
Copy link
Member

Description

The Marten ORM presently allows the create of raw SQL queries for which the whole SQL statement must be provided and whose results are automatically mapped to model instances.

For example:

Article.raw("SELECT * FROM articles WHERE title = ?", "hello")
Article.raw("SELECT * FROM articles WHERE title = :title AND updated_at > :updated_at", title: "hello", updated_at: Time.local)

For cases where it's not needed to specify model field columns directly, it could be interesting to have the ability to filter records by simply providing a raw subquery predicate (eg. title = ?) and the associated parameter(s). When doing so, the resulting query set should allow "chaining" additional filters afterwards if necessary.

For example:

Article.all.filter("title = ?", "hello")
Article.all.filter("title = :title AND updated_at > :updated_at", title: "hello", updated_at: Time.local)

The advantage of doing so is that the selection of the actual model field columns is left to Marten's ORM, which simplifies the use of raw SQL predicates and avoid having to specify full SQL statements.

@ellmetha ellmetha added this to the v0.5.0 milestone Jan 15, 2024
@treagod treagod self-assigned this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants