Yu-Gi-Oh! Deck Building and Card Inventory Management web interface written in Common Lisp, utilizing HTMX.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

77 рядки
2.3KB

  1. #|
  2. Search Session Object
  3. TODO
  4. The idea was I basically just wanted to copy the code from web/search.lisp
  5. Maybe each database object could have their own search sessions? Like
  6. the web deck builder could subclass SEARCH-SESSION with the correct
  7. DEFAULT-INITARGS and relevant CLASS info
  8. |#
  9. (defpackage #:cl-deck-builder2.models.search
  10. (:use #:cl))
  11. (in-package #:cl-deck-builder2.models.search)
  12. ;; TODO Where does this go?
  13. (defparameter +search-param-whitelist+
  14. '("amazon-asin" "barcode" "brand" "buy-price" "category" "code" "created-by"
  15. "deck-id" "desc" "description" "domestic-only" "edition" "email" "id" "kind"
  16. "linkmarkers" "linkval" "manufacturer-sku" "max-qty" "msrp" "parent" "price"
  17. "product-name" "rarity" "rarity-code" "sell-price" "tax-exempt" "total-qty"
  18. "url" "weight" "wishlists" "atk" "def" "level" "scale" "passcode" "type"
  19. "frame-type" "race" "attribute" "archetype" "name" "opt-qty" "qty" "condition")
  20. "A whitelist of keywords allowed by user input on the database side.")
  21. (defclass search-session-base () ())
  22. ;; TODO SLOTs or MAKE-HASH-TABLE? Or an ALIST?
  23. (defclass search-session (search-session-base)
  24. ((direction)
  25. (limit)
  26. (offset)
  27. (sort-by)
  28. (variant))
  29. (:default-initargs
  30. :direction "asc"
  31. :limit 10
  32. :offset 0
  33. :sort-by "id"))
  34. (defmethod initialize-instance :after ((obj search-session) &rest initargs &key &allow-other-keys)
  35. (declare (ignore initargs)))
  36. ;; FILTER-ALIST
  37. (defgeneric search-query-filter (obj))
  38. ;; MAKE-SEARCH-QUERY
  39. (defgeneric search-query-exec (obj))
  40. ;; MAKE-COUNT-QUERY
  41. (defgeneric search-query-count (obj))
  42. ;; MAKE-ORDER-BY
  43. (defgeneric search-query-order-by (obj direction sort-by))
  44. ;; MAKE-WHERE-CLAUSE
  45. (defgeneric search-where-and (obj direction sort-by))
  46. (defun make-sql-clause (op field value)
  47. (let ((op (typecase op
  48. (symbol op)
  49. (string (alexandria:make-keyword (string-upcase
  50. (substitute #\_ #\- op))))))
  51. (field (typecase field
  52. (symbol field)
  53. (string (alexandria:make-keyword (string-upcase
  54. (substitute #\_ #\- field)))))))
  55. (list op field (if (eq op :like)
  56. (format nil "%~a%" value)
  57. value))))
  58. ;; (defun make-kind (kind alist))