aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/model/system.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix-data-service/model/system.scm')
-rw-r--r--guix-data-service/model/system.scm36
1 files changed, 26 insertions, 10 deletions
diff --git a/guix-data-service/model/system.scm b/guix-data-service/model/system.scm
index e64e7f5..d6efa46 100644
--- a/guix-data-service/model/system.scm
+++ b/guix-data-service/model/system.scm
@@ -22,6 +22,7 @@
#:use-module (squee)
#:use-module (guix-data-service model utils)
#:export (system->system-id
+ lookup-system-id
list-systems))
(define system->system-id-cache
@@ -33,17 +34,32 @@
(let ((cached-value (hash-ref system->system-id-cache
system)))
(or cached-value
- (match (insert-missing-data-and-return-all-ids
+ (let ((id (insert-and-return-id
+ conn
+ "systems"
+ '(system)
+ (list system))))
+ (hash-set! system->system-id-cache
+ system
+ id)
+ (set! systems-cache #f)
+ id))))
+
+(define (lookup-system-id conn system)
+ (let ((cached-value (hash-ref system->system-id-cache
+ system)))
+ (or cached-value
+ (match (exec-query
conn
- "systems"
- '(system)
- `((,system)))
- ((id)
- (hash-set! system->system-id-cache
- system
- id)
- (set! systems-cache #f)
- id)))))
+ "SELECT id FROM systems WHERE system = $1"
+ (list system))
+ (((id-string))
+ (let ((id (string->number id-string)))
+ (hash-set! system->system-id-cache
+ system
+ id)
+ id))
+ (() #f)))))
(define (list-systems conn)
(if systems-cache