21 lines
808 B
Common Lisp
21 lines
808 B
Common Lisp
|
(in-package #:cl-deck-builder2-test)
|
||
|
|
||
|
(defun ensure-unique (class field)
|
||
|
"The idea is to select COUNT(*) and then GROUP BY (field) and see if
|
||
|
the number of entries returned is the same."
|
||
|
(let ((count-1
|
||
|
(with-datafly-transaction (db)
|
||
|
(datafly:retrieve-one
|
||
|
(sxql:select ((:as (:count :id) :count))
|
||
|
(sxql:from
|
||
|
(sxql:make-sql-symbol (mito.class:table-name (find-class class))))))))
|
||
|
(count-2
|
||
|
(with-datafly-transaction (db)
|
||
|
(datafly:retrieve-one
|
||
|
(sxql:select ((:as (:count :id) :count))
|
||
|
(sxql:from
|
||
|
(sxql:make-sql-symbol (mito.class:table-name (find-class class))))
|
||
|
(sxql:group-by field))))))
|
||
|
(eq (getf count-1 :count)
|
||
|
(getf count-2 :count))))
|