Skip to content

Register special-syntax function #343

Answered by seancorfield
k3nj1g asked this question in Q&A
Discussion options

You must be logged in to vote

I would expect the original position to come in as nil if it is omitted -- as character does -- but you are shadowing that with your position based on sql-a. That doesn't look like a good way to handle that. I would also recommend against using :inline here since you're opening yourself up the SQL injection attacks.

I'd probably write it like this:

(hsql/register-fn! :trim
                   (fn [_ [text position character]]
                     (let [[sql-t & params-t] (hsql/format-expr text {:nested true})
                           [sql-p & params-p] (when position (hsql/format-expr position {:nested true}))
                           [sql-c & params-c] (when character (hsql/format-expr [

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by k3nj1g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants