Skip to content

Commit bece3ac

Browse files
committed
Document all additional repo functions
1 parent 7f6b3a2 commit bece3ac

1 file changed

Lines changed: 43 additions & 6 deletions

File tree

lib/ecto/adapters/sql.ex

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule Ecto.Adapters.SQL do
2-
@moduledoc """
2+
@moduledoc ~S"""
33
This application provides functionality for working with
44
SQL databases in `Ecto`.
55
@@ -11,9 +11,34 @@ defmodule Ecto.Adapters.SQL do
1111
* `Ecto.Adapters.MyXQL` for MySQL
1212
* `Ecto.Adapters.Tds` for SQLServer
1313
14+
## Additional functions
15+
16+
If your `Ecto.Repo` is backed by any of the SQL adapters above,
17+
this module will inject additional functions into your repository.
18+
These functions can be used by calling the repository or
19+
by calling `Ecto.Adapters.SQL` directly. They are listed below:
20+
21+
* `disconnect_all(interval, options \\ [])` -
22+
shortcut for `Ecto.Adapters.SQL.disconnect_all/3`
23+
24+
* `explain(type, query, options \\ [])` -
25+
shortcut for `Ecto.Adapters.SQL.explain/4`
26+
27+
* `query(sql, params, options \\ [])` -
28+
shortcut for `Ecto.Adapters.SQL.query/4`
29+
30+
* `query!(sql, params, options \\ [])` -
31+
shortcut for `Ecto.Adapters.SQL.query!/4`
32+
33+
* `stream!(sql, params, options \\ [])` -
34+
shortcut for `Ecto.Adapters.SQL.stream/4`
35+
36+
* `to_sql(type, query, options \\ [])` -
37+
shortcut for `Ecto.Adapters.SQL.to_sql/4`
38+
1439
## Migrations
1540
16-
Ecto supports database migrations. You can generate a migration
41+
`ecto_sql` supports database migrations. You can generate a migration
1742
with:
1843
1944
$ mix ecto.gen.migration create_posts
@@ -280,17 +305,21 @@ defmodule Ecto.Adapters.SQL do
280305
Postgrex | `analyze`, `verbose`, `costs`, `settings`, `buffers`, `timing`, `summary`
281306
MyXQL | None
282307
283-
_Postgrex_: Check [PostgreSQL doc](https://www.postgresql.org/docs/current/sql-explain.html) for version compatibility.
308+
_Postgrex_: Check [PostgreSQL doc](https://www.postgresql.org/docs/current/sql-explain.html)
309+
for version compatibility.
284310
285-
_MyXQL_: `EXTENDED` and `PARTITIONS` opts were [deprecated](https://dev.mysql.com/doc/refman/5.7/en/explain.html) and are enabled by default.
311+
_MyXQL_: `EXTENDED` and `PARTITIONS` opts were [deprecated](https://dev.mysql.com/doc/refman/5.7/en/explain.html)
312+
and are enabled by default.
286313
287314
Also note that:
288315
289316
* Currently `:map`, `:yaml`, and `:text` format options are supported
290317
for PostgreSQL. `:map` is the deserialized JSON encoding. The last two
291-
options return the result as a string.
318+
options return the result as a string;
319+
292320
* Any other value passed to `opts` will be forwarded to the underlying
293321
adapter query function, including Repo shared options such as `:timeout`;
322+
294323
* Non built-in adapters may have specific behavior and you should consult
295324
their own documentation.
296325
@@ -516,7 +545,6 @@ defmodule Ecto.Adapters.SQL do
516545
|> IO.iodata_to_binary()
517546
end
518547

519-
520548
defp binary_length(nil), do: 4 # NULL
521549
defp binary_length(binary) when is_binary(binary), do: String.length(binary)
522550
defp binary_length(other), do: other |> inspect() |> String.length()
@@ -577,6 +605,15 @@ defmodule Ecto.Adapters.SQL do
577605
Ecto.Adapters.SQL.query(get_dynamic_repo(), sql, params, opts)
578606
end
579607

608+
@doc """
609+
A convenience function for SQL-based repositories that streams the given query.
610+
611+
See `Ecto.Adapters.SQL.stream/4` for more information.
612+
"""
613+
def stream(sql, params \\ [], opts \\ []) do
614+
Ecto.Adapters.SQL.stream(get_dynamic_repo(), sql, params, opts)
615+
end
616+
580617
@doc """
581618
A convenience function for SQL-based repositories that executes the given query.
582619

0 commit comments

Comments
 (0)