Skip to content

Commit

Permalink
mention in docs about new option
Browse files Browse the repository at this point in the history
  • Loading branch information
dkuku committed Nov 29, 2023
1 parent 528a8d0 commit c12b7cf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/ayesql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,38 @@ defmodule AyeSQL do
]
}
```
AyeSQL also allows you to choose the type of returned data structures.
Instead of the default map you can also pass an into option to your query
possible values are:
- Map or %{}
- Keyword or []
- A struct
- :raw - will return unmodified Postgrex result
```elixir
iex> Queries.get_avg_clicks(params, into: Keyword)
{:ok,
[
[day: ..., count: ...],
[day: ..., count: ...],
[day: ..., count: ...],
...
]
}
```
```elixir
iex> defmodule AvgClicks do defstruct [:day, :count] end
iex> Queries.get_avg_clicks(params, into: AvgClicks)
{:ok,
[
%AvgClicks{day: ..., count: ...},
%AvgClicks{day: ..., count: ...},
%AvgClicks{day: ..., count: ...},
...
]
}
```
"""
alias AyeSQL.Compiler
alias AyeSQL.Query
Expand Down
5 changes: 5 additions & 0 deletions test/support/script.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Runs multiple sql statements
-- name: set_schema
-- type: script
CREATE SCHEMA schema1;
CREATE SCHEMA schema2;

0 comments on commit c12b7cf

Please sign in to comment.