aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/model/utils.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-09-04 19:24:22 +0200
committerChristopher Baines <mail@cbaines.net>2019-09-05 16:07:23 +0200
commitd3913a14d55968e505429693a6df6125e3468300 (patch)
tree8f051b7b8906685297308cb82ea1bcdf2a9eeffe /guix-data-service/model/utils.scm
parent6c90fe432496a2b2ace6984ac24beb7f7736ef1c (diff)
downloaddata-service-d3913a14d55968e505429693a6df6125e3468300.tar
data-service-d3913a14d55968e505429693a6df6125e3468300.tar.gz
Start handling ids as numbers, rather than strings
squee, returns all data as strings, and expects strings as inputs to queries. So, keeping the ids as strings was easy initially, but it means that you can't tell from the type whether it should be quoted, or not... Therefore, handle ids as strings, converting them to numbers when they're fetched from the database, and back to strings as part of the queries.
Diffstat (limited to 'guix-data-service/model/utils.scm')
-rw-r--r--guix-data-service/model/utils.scm15
1 files changed, 7 insertions, 8 deletions
diff --git a/guix-data-service/model/utils.scm b/guix-data-service/model/utils.scm
index 1d187b8..e636988 100644
--- a/guix-data-service/model/utils.scm
+++ b/guix-data-service/model/utils.scm
@@ -165,15 +165,12 @@
'()))
data))
- (define (sort-ids ids)
- (map number->string
- (sort (map string->number ids) <)))
-
(let* ((existing-entries
(exec-query->vhash conn
select-query
cdr
- first))
+ (lambda (result)
+ (string->number (first result)))))
(missing-entries
(filter (lambda (field-values)
(not (vhash-assoc
@@ -187,7 +184,8 @@
(new-entries
(if (null? missing-entries)
'()
- (map first
+ (map (lambda (result)
+ (string->number (first result)))
(exec-query conn (insert-sql missing-entries)))))
(new-entries-lookup-vhash
(two-lists->vhash missing-entries
@@ -197,7 +195,7 @@
(map (lambda (field-value-lists)
;; Normalise the result at this point, ensuring that the id's
;; in the set are sorted
- (sort-ids
+ (sort
(map (lambda (field-values)
(cdr
(or (vhash-assoc (normalise-values field-values)
@@ -205,7 +203,8 @@
(vhash-assoc field-values
new-entries-lookup-vhash)
(error "missing entry" field-values))))
- field-value-lists)))
+ field-value-lists)
+ <))
data)
(map (lambda (field-values)
(cdr