elixir-ecto / db_connection

Database connection behaviour
http://hexdocs.pm/db_connection/DBConnection.html
309 stars 112 forks source link

Allow drivers to return customized `begin` queries. #296

Closed greg-rychlewski closed 1 year ago

greg-rychlewski commented 1 year ago

Problem Statement

I'm looking to add ddl transactions to SQLite. To prevent concurrent migrations I'm trying to use the exclusive transaction shown here: https://www.sqlite.org/lang_transaction.html#deferred_immediate_and_exclusive_transactions

As part of this it would be nice to log/test that the right statements are being executed by the database. But right now db connection will log a generic begin statement because the result from handle_begin is {:ok, result, state}.

Proposal

Allow handle_begin callbacks to return {:ok, query, result, state} in addition to {:ok, result, state} for drivers that can use customized begin queries. This would mirror the way handle_execute enables logging.

v0idpwn commented 1 year ago

I don't see why not, API seems good.

josevalim commented 1 year ago

Sounds good to me!