0

I want to created post as return value just after execute my db query function. Here is one example from my db functions:

(defn add-post-record [post]
   (sql/with-connection
    db
    (sql/insert-record :post post )))

and what i need in my route is something like:

(def post (db/add-post-record {:title title
                             :body body
                             :owner user
                             :isdraft isdraft}))

Then i am gonna use this like: (:id post)

I am so new in clojure. This may be a very simple problem but i am stuck.

thank you.

1 Answer 1

1

I can not test this right now, but reading the documentation of insert-record and with-connection, I think something like:

(defn add-post-record [post]
 (let [keys (sql/with-connection db
              (sql/insert-record :post post ))]
   (merge post keys))

It is not very clear to me what exactly the map returned by insert-record contains, try it out.

Sign up to request clarification or add additional context in comments.

1 Comment

i am gonna check this out a few hours later. gonna tell you the result. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.