From 480526fe804c711b455630da1add0be7e8ea39b2 Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Thu, 5 Oct 2023 03:19:13 -0400 Subject: [PATCH] format lib/**/*.ex --- .formatter.exs | 3 +- lib/ecto/adapters/myxql/connection.ex | 2 +- lib/ecto/adapters/postgres/connection.ex | 6 +- lib/ecto/adapters/sql/application.ex | 2 +- lib/ecto/adapters/sql/connection.ex | 79 +++++++++++++++--------- lib/ecto/adapters/sql/sandbox.ex | 9 +++ lib/ecto/adapters/tds/connection.ex | 4 +- 7 files changed, 66 insertions(+), 39 deletions(-) diff --git a/.formatter.exs b/.formatter.exs index f80a11a9..bc83f31c 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -30,6 +30,5 @@ locals_without_parens = [ locals_without_parens: locals_without_parens, export: [ locals_without_parens: locals_without_parens - ], - inputs: [] + ] ] diff --git a/lib/ecto/adapters/myxql/connection.ex b/lib/ecto/adapters/myxql/connection.ex index 02effd29..a1e86308 100644 --- a/lib/ecto/adapters/myxql/connection.ex +++ b/lib/ecto/adapters/myxql/connection.ex @@ -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} -> diff --git a/lib/ecto/adapters/postgres/connection.ex b/lib/ecto/adapters/postgres/connection.ex index 9e868b4a..aa140a7c 100644 --- a/lib/ecto/adapters/postgres/connection.ex +++ b/lib/ecto/adapters/postgres/connection.ex @@ -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 @@ -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} -> @@ -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} -> diff --git a/lib/ecto/adapters/sql/application.ex b/lib/ecto/adapters/sql/application.ex index 682f1625..88712fdc 100644 --- a/lib/ecto/adapters/sql/application.ex +++ b/lib/ecto/adapters/sql/application.ex @@ -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] diff --git a/lib/ecto/adapters/sql/connection.ex b/lib/ecto/adapters/sql/connection.ex index 9b08b21c..0b311754 100644 --- a/lib/ecto/adapters/sql/connection.ex +++ b/lib/ecto/adapters/sql/connection.ex @@ -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 @@ -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`. @@ -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. @@ -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 diff --git a/lib/ecto/adapters/sql/sandbox.ex b/lib/ecto/adapters/sql/sandbox.ex index 35a90714..985b7981 100644 --- a/lib/ecto/adapters/sql/sandbox.ex +++ b/lib/ecto/adapters/sql/sandbox.ex @@ -335,14 +335,17 @@ 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]) @@ -350,16 +353,22 @@ defmodule Ecto.Adapters.SQL.Sandbox do 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)]) diff --git a/lib/ecto/adapters/tds/connection.ex b/lib/ecto/adapters/tds/connection.ex index 579790b2..842acaac 100644 --- a/lib/ecto/adapters/tds/connection.ex +++ b/lib/ecto/adapters/tds/connection.ex @@ -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 @@ -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} ->