|
62 | 62 | #:recreate-table
|
63 | 63 | #:ensure-table-exists
|
64 | 64 | #:deftable
|
65 |
| - #:do-cursor)) |
| 65 | + #:do-select)) |
66 | 66 | (in-package #:mito.dao)
|
67 | 67 |
|
68 | 68 | (defun foreign-value (obj slot)
|
|
453 | 453 | `((:conc-name ,(intern (format nil "~@:(~A-~)" name) (symbol-package name)))))
|
454 | 454 | ,@options))
|
455 | 455 |
|
456 |
| -(defmacro do-cursor ((dao select &optional index) &body body) |
457 |
| - (with-gensyms (main cursor) |
458 |
| - `(flet ((,main () |
459 |
| - (let* ((*want-cursor* t) |
460 |
| - (,cursor ,select)) |
461 |
| - (loop ,@(and index `(for ,index from 0)) |
462 |
| - for ,dao = (fetch-dao-from-cursor ,cursor) |
463 |
| - while ,dao |
464 |
| - do (progn ,@body))))) |
465 |
| - (if (dbi:in-transaction *connection*) |
466 |
| - (,main) |
467 |
| - (dbi:with-transaction *connection* |
468 |
| - (,main)))))) |
| 456 | +(defmacro do-select ((dao select &optional index) &body body) |
| 457 | + (with-gensyms (main main-body select-fn cursor i) |
| 458 | + `(block nil |
| 459 | + (labels ((,main-body (,dao ,(or index i)) |
| 460 | + ,@(and (not index) |
| 461 | + `((declare (ignore ,i)))) |
| 462 | + ,@body) |
| 463 | + (,select-fn () ,select) |
| 464 | + (,main () |
| 465 | + (case (dbi:connection-driver-type *connection*) |
| 466 | + (:postgres |
| 467 | + (let ((,cursor (let ((*want-cursor* t)) |
| 468 | + (,select-fn)))) |
| 469 | + (loop ,@(and index `(for ,i from 0)) |
| 470 | + for ,dao = (fetch-dao-from-cursor ,cursor) |
| 471 | + while ,dao |
| 472 | + do (,main-body ,dao ,i)))) |
| 473 | + (otherwise |
| 474 | + (loop ,@(and index `(for ,i from 0)) |
| 475 | + for ,dao in (,select-fn) |
| 476 | + do (,main-body ,dao ,i)))))) |
| 477 | + (if (dbi:in-transaction *connection*) |
| 478 | + (,main) |
| 479 | + (dbi:with-transaction *connection* |
| 480 | + (,main))))))) |
0 commit comments