cbaines pushed a commit to branch master
in repository data-service.
commit 9a38374e7c27e41f592f457c53e1b187b08b7d59
Author: Christopher Baines <[email protected]>
AuthorDate: Fri Nov 29 13:47:40 2024 +0000
Use insert-missing-data-and-return-all-ids for locations
---
guix-data-service/model/location.scm | 38 +++++++++---------------------------
1 file changed, 9 insertions(+), 29 deletions(-)
diff --git a/guix-data-service/model/location.scm
b/guix-data-service/model/location.scm
index 6e010da..630251c 100644
--- a/guix-data-service/model/location.scm
+++ b/guix-data-service/model/location.scm
@@ -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)))))))