@@ -492,10 +492,16 @@ defmodule Ecto.Adapters.SQL do
492492 """
493493
494494 @ doc @ to_sql_doc
495- @ spec to_sql ( :all | :update_all | :delete_all , Ecto.Repo . t ( ) , Ecto.Queryable . t ( ) ) ::
495+ @ spec to_sql ( :all | :update_all | :delete_all , Ecto.Repo . t ( ) , Ecto.Queryable . t ( ) , Keyword . t ( ) ) ::
496496 { String . t ( ) , query_params }
497- def to_sql ( kind , repo , queryable ) do
498- case Ecto.Adapter.Queryable . prepare_query ( kind , repo , queryable ) do
497+ def to_sql ( kind , repo , queryable , opts \\ [ ] ) do
498+ prepare_opts =
499+ case Keyword . fetch ( opts , :counter ) do
500+ { :ok , counter } -> [ counter: counter ]
501+ :error -> [ ]
502+ end
503+
504+ case Ecto.Adapter.Queryable . prepare_query ( kind , repo , queryable , prepare_opts ) do
499505 { { :cached , _update , _reset , { _id , cached } } , params } ->
500506 { String.Chars . to_string ( cached ) , params }
501507
@@ -825,10 +831,10 @@ defmodule Ecto.Adapters.SQL do
825831 end
826832
827833 @ doc unquote ( to_sql_doc )
828- @ spec to_sql ( :all | :update_all | :delete_all , Ecto.Queryable . t ( ) ) ::
834+ @ spec to_sql ( :all | :update_all | :delete_all , Ecto.Queryable . t ( ) , Keyword . t ( ) ) ::
829835 { String . t ( ) , Ecto.Adapters.SQL . query_params ( ) }
830- def to_sql ( operation , queryable ) do
831- Ecto.Adapters.SQL . to_sql ( operation , get_dynamic_repo ( ) , queryable )
836+ def to_sql ( operation , queryable , opts \\ [ ] ) do
837+ Ecto.Adapters.SQL . to_sql ( operation , get_dynamic_repo ( ) , queryable , opts )
832838 end
833839
834840 @ doc unquote ( explain_doc )
0 commit comments