alexdesousa / ayesql

Library for using raw SQL in Elixir
MIT License
138 stars 14 forks source link

infinite recursion prevention #42

Open bglusman opened 2 weeks ago

bglusman commented 2 weeks ago

If a query named :x contains a reference to :x as a parameter inside it, it will trigger infinite recursion.... this should probably be detected and prevented with a clear error for improved developer experience

alexdesousa commented 1 week ago

Certainly, this would help developer experience! When I was building an example for #41 I run into this issue. Basically, I had a fragment with a the same name as the parameter:

-- name: limit
LIMIT :limit

and I fixed it with:

-- name: limit
LIMIT :rows

This would be a nice to have in the future.

bglusman commented 1 week ago

Yeah, that's exactly the situation I hit it in, maybe not limit but same idea. While I was making the other PR I was thinking about how I'd do this one too, it didn't look simple, but I also didn't get that far into understanding how the templates were compiled. If you get around to it, awesome, if you'd like me to take a crack at, LMK, but a little high level guidance for what you think best approach might be would be appreciated. Thank!