Skip to content

Commit

Permalink
Make do-select work even with select-by-sql.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Aug 9, 2024
1 parent 7c71f59 commit 1e99b02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,8 @@ Since `insert-dao`, `update-dao` and `delete-dao` are defined as generic functio
do (return dao))
```

The query form must be one of `select-dao`, `retrieve-dao`, or `select-by-sql`.

## Installation

```common-lisp
Expand Down
22 changes: 12 additions & 10 deletions src/core/dao.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,16 @@
collect value)))))

(defun select-by-sql (class sql &key binds)
(mapcar (lambda (result)
(apply #'make-dao-instance class result))
(retrieve-by-sql sql :binds binds)))
(if *want-cursor*
(select-by-sql-as-cursor class sql :binds binds)
(mapcar (lambda (result)
(apply #'make-dao-instance class result))
(retrieve-by-sql sql :binds binds))))

(defun include-foreign-objects (foreign-class records)
(when records
(let ((foreign-class (ensure-class foreign-class)))
(let ((*want-cursor* nil)
(foreign-class (ensure-class foreign-class)))
(when (cdr (table-primary-key foreign-class))
(error "Cannot use 'includes' with a class which has composite primary keys."))
(let* ((class (class-of (first records)))
Expand Down Expand Up @@ -360,12 +363,11 @@
(dolist (,clause (list ,@clauses))
(when ,clause
(add-child ,sql ,clause)))
(if *want-cursor*
(select-by-sql-as-cursor ,class ,sql)
(let ((,results (select-by-sql ,class ,sql)))
(dolist (,foreign-class (remove-duplicates ,include-classes))
(include-foreign-objects ,foreign-class ,results))
(values ,results ,sql)))))))))))
(let ((,results (select-by-sql ,class ,sql)))
(unless *want-cursor*
(dolist (,foreign-class (remove-duplicates ,include-classes))
(include-foreign-objects ,foreign-class ,results)))
(values ,results ,sql))))))))))

(defun where-and (fields-and-values class)
(when fields-and-values
Expand Down

0 comments on commit 1e99b02

Please sign in to comment.