alexdesousa / ayesql

Library for using raw SQL in Elixir
MIT License
135 stars 13 forks source link

How to parameterize "do" block? #30

Closed dvv closed 11 months ago

dvv commented 2 years ago

Hello!

I wonder is there a way do pass arguments to anonymous blocks such as:

-- name: anon_1
-- docs: anon_1
do $$
    raise exception 'err: %', :err -- err is an arg
$$

The rationale is e.g. to perform a series of coupled actions or to wrap some actions on db with common exception handler.

TIA

alexdesousa commented 11 months ago

@dvv I know this answer comes very late, but the reason DO blocks are not supported is because they are strings evaluated in the database. For this reason, Postgrex doesn't evaluate them before sending them to the database. That means AyeSQL (which is a wrapper over Postgrex) cannot do it.