Capture Racket query return value

Asked

Viewed 40 times

1

Hello, I’m a beginner in Racket. I would like to capture the value Insert-id that returns in a flame struct simple-result of query which I execute. The return is as follows:

(simple-result '((insert-id . 30) (affected-rows . 1)))

I’d like to get the value 30 for example.

Code of execution of the query:

(define save_pergunta 
  (lambda (tf_pergunta)
  (define result_save_pergunta (
      query conn "INSERT INTO perguntas VALUES (null, $pergunta)" tf_pergunta))
  (print result_save_pergunta)
  (printf "\nPergunta Cadastrada!\n")))

1 answer

0


I was able to accomplish what I needed with the function Dict-ref passing the query and the identifier as parameters.

Thus remaining:

(define save_pergunta 
 (lambda (tf_pergunta)
  (define result_save_pergunta (
       dict-ref (
           query conn "INSERT INTO perguntas VALUES (null, $pergunta)" tf_pergunta) 'insert-id)
  (print result_save_pergunta)
  (printf "\nPergunta Cadastrada!\n")))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.