Skip to content

Commit

Permalink
format lib/**/*.ex
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski committed Oct 5, 2023
1 parent 2df2896 commit 480526f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 39 deletions.
3 changes: 1 addition & 2 deletions .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ locals_without_parens = [
locals_without_parens: locals_without_parens,
export: [
locals_without_parens: locals_without_parens
],
inputs: []
]
]
2 changes: 1 addition & 1 deletion lib/ecto/adapters/myxql/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ if Code.ensure_loaded?(MyXQL) do
{:fragment, _, _} ->
{nil, as_prefix ++ [?f | Integer.to_string(pos)], nil}

{:values, _, _} ->
{:values, _, _} ->
{nil, as_prefix ++ [?v | Integer.to_string(pos)], nil}

{table, schema, prefix} ->
Expand Down
6 changes: 3 additions & 3 deletions lib/ecto/adapters/postgres/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ if Code.ensure_loaded?(Postgrex) do

defp values_expr(types, idx) do
intersperse_reduce(types, ?,, idx, fn {_field, type}, idx ->
{[?$ , Integer.to_string(idx), ?:, ?: | tagged_to_db(type)], idx + 1}
{[?$, Integer.to_string(idx), ?:, ?: | tagged_to_db(type)], idx + 1}
end)
end

Expand Down Expand Up @@ -1131,7 +1131,7 @@ if Code.ensure_loaded?(Postgrex) do
{:fragment, _, _} ->
{nil, as_prefix ++ [?f | Integer.to_string(pos)], nil}

{:values, _, _} ->
{:values, _, _} ->
{nil, as_prefix ++ [?v | Integer.to_string(pos)], nil}

{table, schema, prefix} ->
Expand Down Expand Up @@ -1375,7 +1375,7 @@ if Code.ensure_loaded?(Postgrex) do

defp comments_for_columns(table_name, columns) do
Enum.flat_map(columns, fn
{:remove, _column_name, _column_type, _opts} ->
{:remove, _column_name, _column_type, _opts} ->
[]

{_operation, column_name, _column_type, opts} ->
Expand Down
2 changes: 1 addition & 1 deletion lib/ecto/adapters/sql/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Ecto.Adapters.SQL.Application do
def start(_type, _args) do
children = [
{DynamicSupervisor, strategy: :one_for_one, name: Ecto.MigratorSupervisor},
{Task.Supervisor, name: Ecto.Adapters.SQL.StorageSupervisor},
{Task.Supervisor, name: Ecto.Adapters.SQL.StorageSupervisor}
]

opts = [strategy: :one_for_one, name: Ecto.Adapters.SQL.Supervisor]
Expand Down
79 changes: 49 additions & 30 deletions lib/ecto/adapters/sql/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ defmodule Ecto.Adapters.SQL.Connection do
"""

@typedoc "The query name"
@type name :: String.t
@type name :: String.t()

@typedoc "The SQL statement"
@type statement :: String.t
@type statement :: String.t()

@typedoc "The cached query which is a DBConnection Query"
@type cached :: map
Expand All @@ -19,38 +19,38 @@ defmodule Ecto.Adapters.SQL.Connection do
Receives options and returns `DBConnection` supervisor child
specification.
"""
@callback child_spec(options :: Keyword.t) :: :supervisor.child_spec() | {module, Keyword.t}
@callback child_spec(options :: Keyword.t()) :: :supervisor.child_spec() | {module, Keyword.t()}

@doc """
Prepares and executes the given query with `DBConnection`.
"""
@callback prepare_execute(connection, name, statement, params, options :: Keyword.t) ::
{:ok, cached, term} | {:error, Exception.t}
@callback prepare_execute(connection, name, statement, params, options :: Keyword.t()) ::
{:ok, cached, term} | {:error, Exception.t()}

@doc """
Executes a cached query.
"""
@callback execute(connection, cached, params, options :: Keyword.t) ::
{:ok, cached, term} | {:ok, term} | {:error | :reset, Exception.t}
@callback execute(connection, cached, params, options :: Keyword.t()) ::
{:ok, cached, term} | {:ok, term} | {:error | :reset, Exception.t()}

@doc """
Runs the given statement as a query.
"""
@callback query(connection, statement, params, options :: Keyword.t) ::
{:ok, term} | {:error, Exception.t}
@callback query(connection, statement, params, options :: Keyword.t()) ::
{:ok, term} | {:error, Exception.t()}

@doc """
Runs the given statement as a multi-result query.
"""
@callback query_many(connection, statement, params, options :: Keyword.t) ::
{:ok, term} | {:error, Exception.t}
@callback query_many(connection, statement, params, options :: Keyword.t()) ::
{:ok, term} | {:error, Exception.t()}

@doc """
Returns a stream that prepares and executes the given query with
`DBConnection`.
"""
@callback stream(connection, statement, params, options :: Keyword.t) ::
Enum.t
@callback stream(connection, statement, params, options :: Keyword.t()) ::
Enum.t()

@doc """
Receives the exception returned by `c:query/4`.
Expand All @@ -64,46 +64,60 @@ defmodule Ecto.Adapters.SQL.Connection do
Must return an empty list if the error does not come
from any constraint.
"""
@callback to_constraints(exception :: Exception.t, options :: Keyword.t) :: Keyword.t
@callback to_constraints(exception :: Exception.t(), options :: Keyword.t()) :: Keyword.t()

## Queries

@doc """
Receives a query and must return a SELECT query.
"""
@callback all(query :: Ecto.Query.t) :: iodata
@callback all(query :: Ecto.Query.t()) :: iodata

@doc """
Receives a query and values to update and must return an UPDATE query.
"""
@callback update_all(query :: Ecto.Query.t) :: iodata
@callback update_all(query :: Ecto.Query.t()) :: iodata

@doc """
Receives a query and must return a DELETE query.
"""
@callback delete_all(query :: Ecto.Query.t) :: iodata
@callback delete_all(query :: Ecto.Query.t()) :: iodata

@doc """
Returns an INSERT for the given `rows` in `table` returning
the given `returning`.
"""
@callback insert(prefix ::String.t, table :: String.t,
header :: [atom], rows :: [[atom | nil]],
on_conflict :: Ecto.Adapter.Schema.on_conflict, returning :: [atom],
placeholders :: [term]) :: iodata
@callback insert(
prefix :: String.t(),
table :: String.t(),
header :: [atom],
rows :: [[atom | nil]],
on_conflict :: Ecto.Adapter.Schema.on_conflict(),
returning :: [atom],
placeholders :: [term]
) :: iodata

@doc """
Returns an UPDATE for the given `fields` in `table` filtered by
`filters` returning the given `returning`.
"""
@callback update(prefix :: String.t, table :: String.t, fields :: [atom],
filters :: [atom], returning :: [atom]) :: iodata
@callback update(
prefix :: String.t(),
table :: String.t(),
fields :: [atom],
filters :: [atom],
returning :: [atom]
) :: iodata

@doc """
Returns a DELETE for the `filters` returning the given `returning`.
"""
@callback delete(prefix :: String.t, table :: String.t,
filters :: [atom], returning :: [atom]) :: iodata
@callback delete(
prefix :: String.t(),
table :: String.t(),
filters :: [atom],
returning :: [atom]
) :: iodata

@doc """
Executes an EXPLAIN query or similar depending on the adapter to obtains statistics of the given query.
Expand All @@ -113,23 +127,28 @@ defmodule Ecto.Adapters.SQL.Connection do
Must execute the explain query and return the result.
"""
@callback explain_query(connection, query :: String.t, params :: Keyword.t, opts :: Keyword.t) ::
{:ok, term} | {:error, Exception.t}
@callback explain_query(
connection,
query :: String.t(),
params :: Keyword.t(),
opts :: Keyword.t()
) ::
{:ok, term} | {:error, Exception.t()}

## DDL

@doc """
Receives a DDL command and returns a query that executes it.
"""
@callback execute_ddl(command :: Ecto.Adapter.Migration.command) :: String.t | [iodata]
@callback execute_ddl(command :: Ecto.Adapter.Migration.command()) :: String.t() | [iodata]

@doc """
Receives a query result and returns a list of logs.
"""
@callback ddl_logs(result :: term) :: [{Logger.level, Logger.message, Logger.metadata}]
@callback ddl_logs(result :: term) :: [{Logger.level(), Logger.message(), Logger.metadata()}]

@doc """
Returns a queryable to check if the given `table` exists.
"""
@callback table_exists_query(table :: String.t) :: {iodata, [term]}
@callback table_exists_query(table :: String.t()) :: {iodata, [term]}
end
9 changes: 9 additions & 0 deletions lib/ecto/adapters/sql/sandbox.ex
Original file line number Diff line number Diff line change
Expand Up @@ -335,31 +335,40 @@ defmodule Ecto.Adapters.SQL.Sandbox do
case conn_mod.handle_begin(opts, state) do
{:ok, value, state} ->
{:ok, value, {conn_mod, state, true}}

{kind, err, state} ->
{kind, err, {conn_mod, state, false}}
end
end

def handle_commit(opts, {conn_mod, state, true}) do
opts = [mode: :savepoint] ++ opts
proxy(:handle_commit, {conn_mod, state, false}, [opts])
end

def handle_rollback(opts, {conn_mod, state, _}) do
opts = [mode: :savepoint] ++ opts
proxy(:handle_rollback, {conn_mod, state, false}, [opts])
end

def handle_status(opts, state),
do: proxy(:handle_status, state, [maybe_savepoint(opts, state)])

def handle_prepare(query, opts, state),
do: proxy(:handle_prepare, state, [query, maybe_savepoint(opts, state)])

def handle_execute(query, params, opts, state),
do: proxy(:handle_execute, state, [query, params, maybe_savepoint(opts, state)])

def handle_close(query, opts, state),
do: proxy(:handle_close, state, [query, maybe_savepoint(opts, state)])

def handle_declare(query, params, opts, state),
do: proxy(:handle_declare, state, [query, params, maybe_savepoint(opts, state)])

def handle_fetch(query, cursor, opts, state),
do: proxy(:handle_fetch, state, [query, cursor, maybe_savepoint(opts, state)])

def handle_deallocate(query, cursor, opts, state),
do: proxy(:handle_deallocate, state, [query, cursor, maybe_savepoint(opts, state)])

Expand Down
4 changes: 2 additions & 2 deletions lib/ecto/adapters/tds/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ if Code.ensure_loaded?(Tds) do

defp values_expr(types, idx) do
intersperse_reduce(types, ?,, idx, fn {_field, type}, idx ->
{["CAST(", ?@ , Integer.to_string(idx), " AS ", column_type(type, []), ?)], idx + 1}
{["CAST(", ?@, Integer.to_string(idx), " AS ", column_type(type, []), ?)], idx + 1}
end)
end

Expand Down Expand Up @@ -1031,7 +1031,7 @@ if Code.ensure_loaded?(Tds) do
{:fragment, _, _} ->
{nil, as_prefix ++ [?f | Integer.to_string(pos)], nil}

{:values, _, _} ->
{:values, _, _} ->
{nil, as_prefix ++ [?v | Integer.to_string(pos)], nil}

{table, model, prefix} ->
Expand Down

0 comments on commit 480526f

Please sign in to comment.