mirror of
git://git.savannah.gnu.org/guix/guix-cuirass.git
synced 2023-12-14 06:03:04 +01:00
database: Turn 'sqlite-exec' into a macro.
* src/cuirass/database.scm (%sqlite-exec): New procedure. (sqlite-exec): New macro.
This commit is contained in:
parent
49a341866a
commit
c4963deca1
|
@ -53,11 +53,8 @@
|
||||||
;; Macros.
|
;; Macros.
|
||||||
with-database))
|
with-database))
|
||||||
|
|
||||||
(define (sqlite-exec db msg . args)
|
(define (%sqlite-exec db sql)
|
||||||
"Wrap 'sqlite-prepare', 'sqlite-step', and 'sqlite-finalize'. Send message
|
(let* ((stmt (sqlite-prepare db sql))
|
||||||
MSG to database DB. MSG and ARGS are passed to 'format'."
|
|
||||||
(let* ((sql (apply format #f msg args))
|
|
||||||
(stmt (sqlite-prepare db sql))
|
|
||||||
(res (let loop ((res '()))
|
(res (let loop ((res '()))
|
||||||
(let ((row (sqlite-step stmt)))
|
(let ((row (sqlite-step stmt)))
|
||||||
(if (not row)
|
(if (not row)
|
||||||
|
@ -66,6 +63,19 @@ MSG to database DB. MSG and ARGS are passed to 'format'."
|
||||||
(sqlite-finalize stmt)
|
(sqlite-finalize stmt)
|
||||||
res))
|
res))
|
||||||
|
|
||||||
|
(define-syntax sqlite-exec
|
||||||
|
;; Note: Making it a macro so -Wformat can do its job.
|
||||||
|
(lambda (s)
|
||||||
|
"Wrap 'sqlite-prepare', 'sqlite-step', and 'sqlite-finalize'. Send to given
|
||||||
|
SQL statement to DB. FMT and ARGS are passed to 'format'."
|
||||||
|
(syntax-case s ()
|
||||||
|
((_ db fmt args ...)
|
||||||
|
#'(%sqlite-exec db (format #f fmt args ...)))
|
||||||
|
(id
|
||||||
|
(identifier? #'id)
|
||||||
|
#'(lambda (db fmt . args)
|
||||||
|
(%sqlite-exec db (apply format #f fmt args)))))))
|
||||||
|
|
||||||
(define %package-database
|
(define %package-database
|
||||||
;; Define to the database file name of this package.
|
;; Define to the database file name of this package.
|
||||||
(make-parameter (string-append %localstatedir "/run/" %package
|
(make-parameter (string-append %localstatedir "/run/" %package
|
||||||
|
|
Loading…
Reference in a new issue