From 9a38374e7c27e41f592f457c53e1b187b08b7d59 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 29 Nov 2024 13:47:40 +0000 Subject: [PATCH] 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 - (($ 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 + (($ file line column) + (list (list file line column)))))))