Capture return value from query Racket

0

Hello, I'm a beginner on the racket. I would like to capture the insert-id value that returns in a struct called simple-result da query file that I run. The return is as follows:

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

I would like to get the value 30 for example.

Query execution code:

(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")))
    
asked by anonymous 27.09.2018 / 21:23

1 answer

0

I was able to accomplish what I needed with the # by passing the query and the identifier as parameters.

Getting this way:

(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")))
    
28.09.2018 / 22:42