Add a has-instance-with-id function to check the existance of an instance. Also fix the count-instance function.
This commit is contained in:
parent
d51866a5e5
commit
6553f10979
|
@ -23,6 +23,7 @@
|
|||
save-instance
|
||||
save-instances
|
||||
find-instance-by-id
|
||||
has-instance-with-id
|
||||
list-instances
|
||||
find-instances
|
||||
count-instances
|
||||
|
@ -270,6 +271,18 @@
|
|||
(set-struct:stored-instance-identifier! instance id)
|
||||
instance))
|
||||
|
||||
; Check if an instance with the given id exists
|
||||
(define/contract (has-instance-with-id cls id)
|
||||
(-> struct:stored-class? integer? boolean?)
|
||||
(define repo (struct:stored-class-repository cls))
|
||||
(define conn (struct:repository-connection repo))
|
||||
(define row (query-row
|
||||
conn
|
||||
(format "select count(*) from ~a where rowid = ?"
|
||||
(struct:stored-class-name cls))
|
||||
id))
|
||||
(> (vector-ref row 0) 0))
|
||||
|
||||
; Return a list of instances
|
||||
(define (list-instances cls #:limit (limit #f) #:offset (offset #f) #:descending (desc #f))
|
||||
(let* ((repo (struct:stored-class-repository cls))
|
||||
|
@ -353,7 +366,9 @@
|
|||
(let* ((repo (struct:stored-class-repository cls))
|
||||
(conn (struct:repository-connection repo))
|
||||
)
|
||||
(query-value conn (format "select count(*) from ~a" (struct:stored-class-name cls)))))
|
||||
(vector-ref
|
||||
(query-value conn (format "select count(*) from ~a" (struct:stored-class-name cls)))
|
||||
0)))
|
||||
|
||||
; Store an instance
|
||||
; Create a new instance in the repository
|
||||
|
|
Loading…
Reference in New Issue