Skip to content

Commit

Permalink
Adding guides on raw where escape hatch. Fixes #1320
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink committed Jul 21, 2024
1 parent 30c7eb6 commit df3e247
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit df3e247

Please sign in to comment.