Skip to content

Commit

Permalink
closql--iref: Use sql join and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Jan 25, 2024
1 parent be2721c commit 09ad40f
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions closql.el
Original file line number Diff line number Diff line change
Expand Up @@ -621,23 +621,18 @@
(defun closql--iref (obj slot)
(pcase-let*
((db (closql--oref obj 'closql-database))
(`(,d-table ,i-table)
(`(,slot-table ,data-table)
(closql--slot-tables obj slot))
(d-cols (closql--table-columns db d-table "d"))
(i-cols (closql--table-columns db i-table "i"))
(obj-id (closql--oref obj (oref-default obj closql-primary-key))))
(emacsql db [:select :distinct $i1
:from [(as $i2 d)
(as $i3 i)]
:where (and (= $i4 $i5)
(= $i6 $s7))]
(vconcat (cddr i-cols))
d-table
i-table
(cadr d-cols)
(cadr i-cols)
(car d-cols)
obj-id)))
(`(,where ,slot-join) (closql--table-columns db slot-table))
(`(,_ ,data-join . ,select) (closql--table-columns db data-table))
(object-id (closql--oref obj (oref-default obj closql-primary-key))))
(emacsql db [:select $i1 :from $i2 :join $i3
:on (= $i4 $i5)
:where (= $i6 $s7)]
(vconcat select) data-table slot-table
(intern (format "%s:%s" slot-table slot-join))
(intern (format "%s:%s" data-table data-join))
where object-id)))

(defun closql--slot-tables (obj slot)
(let ((tables (closql--slot-get obj slot :closql-table)))
Expand Down

0 comments on commit 09ad40f

Please sign in to comment.