Fork me on GitHub
#sql
<
2022-02-07
>
pinkfrog08:02:31

I have formatted the DSL with sql/format. Now given the vector, is it convert it to the normal sql string as if I have formatted with the inline true firsthand?

seancorfield16:02:13

@i I don't understand your question - can you provide a small example?

pinkfrog00:02:05

(-> (select :tb)
    (sql/format)
the above gives a vector based representation. Given the above result, I want to have the inline form, as if I have used (sql/format :inline) initially.

seancorfield01:02:29

Why not just use (sql/format :inline true) then?

seancorfield01:02:42

(and this is a question for #honeysql not #sql really)

seancorfield01:02:24

Also be aware that using :inline formatting can open you up to SQL injection attacks so it's not something you generally want to do in production code.

pinkfrog01:02:45

> Why not just use `(sql/format :inline true)` then? The function is written without :inline. But sometimes for convenience I’d like to copy-paste the result in a inline form and instead of vector form to the sql console.

seancorfield01:02:00

Then refactor the code. Split that function into one that just builds the data structure and call that from the current function with (sql/format) as-is. Then you can call that new function and wrap it in (sql/format :inline true) when you want the inline result for your SQL console.

seancorfield01:02:35

Or add an optional argument that lets you invoke the original function with the :inline flag passed in.

seancorfield01:02:52

(although I'd be wary of encouraging other users of that code to produce inline-formatted SQL because of the injection potential)

orestis10:02:43

TIL about the inline option!