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

Adding guides on raw where escape hatch #1340

Merged
merged 1 commit into from
Jul 21, 2024
Merged
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
11 changes: 11 additions & 0 deletions src/actions/guides/database/querying.cr
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,17 @@ class Guides::Database::Querying < GuideAction
> For each supported time unit, you can either pass it as an enum value to `extract` (i.e. `extract(Avram::ChronoUnits::Year)`)
> or append the lowercase version to `extract_` (i.e. `extract_julian`)

### Raw Where Queries

For more complex queries, and as an escape hatch to support queries beyond Avram's support, you can pass raw strings to
`where` and use the `?` character as a value placeholder. The arguments after the first are the values to be replaced in the query.

```crystal
UserQuery.new.where("preferences->>'theme' = ? AND preferences->>'version' = ?", "rose", "v2")
```

> Due to the placeholder character being a `?`, some jsonb operations won't work here. (e.g. `jsonb ? text`)

## Order By

Return rows ordered by the `age` column in descending (or ascending) order.
Expand Down
Loading