Use insert-missing-data-and-return-all-ids for locations
This commit is contained in:
parent
221394eafb
commit
9a38374e7c
1 changed files with 9 additions and 29 deletions
|
|
@ -19,35 +19,15 @@
|
|||
#:use-module (ice-9 match)
|
||||
#:use-module (guix utils)
|
||||
#:use-module (squee)
|
||||
#:use-module (guix-data-service model utils)
|
||||
#:export (location->location-id))
|
||||
|
||||
(define select-existing-location
|
||||
(string-append
|
||||
"SELECT id "
|
||||
"FROM locations "
|
||||
"WHERE file = $1 AND line = $2 AND column_number = $3"))
|
||||
|
||||
(define insert-location
|
||||
(string-append
|
||||
"INSERT INTO locations "
|
||||
"(file, line, column_number) VALUES "
|
||||
"($1, $2, $3) "
|
||||
"RETURNING id"))
|
||||
|
||||
(define (location->location-id conn location)
|
||||
(match location
|
||||
(($ <location> file line column)
|
||||
(string->number
|
||||
(match (exec-query conn
|
||||
select-existing-location
|
||||
(list file
|
||||
(number->string line)
|
||||
(number->string column)))
|
||||
(((id)) id)
|
||||
(()
|
||||
(caar
|
||||
(exec-query conn
|
||||
insert-location
|
||||
(list file
|
||||
(number->string line)
|
||||
(number->string column))))))))))
|
||||
(car
|
||||
(insert-missing-data-and-return-all-ids
|
||||
conn
|
||||
"locations"
|
||||
'(file line column_number)
|
||||
(match location
|
||||
(($ <location> file line column)
|
||||
(list (list file line column)))))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue