fukamachi / mito

An ORM for Common Lisp with migrations, relationships and PostgreSQL support
284 stars 31 forks source link

Cursor support (only for PostgreSQL) #150

Closed fukamachi closed 1 month ago

fukamachi commented 1 month ago

This adds an RDB's CURSOR support to select-dao, which can reduce memory usage since it won't load whole results on memory.

A new macro do-cursor loops through rows one by one as a DAO:

(do-cursor (dao (select-dao 'user
                  (where (:< "2024-07-01" :created_at))))
  ;; Can be a more complex condition
  (when (equal (user-name dao) "Eitaro")
    (return dao)))

;; Same but without using CURSOR
(loop for dao in (select-dao 'user
                   (where (:< "2024-07-01" :created_at)))
      when (equal (user-name dao) "Eitaro")
      do (return dao))

It requires DBI v0.11.1 or above.