Skip to content

Commit

Permalink
Restore ability to set :closql-tables slots
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Jul 1, 2024
1 parent 7ab214c commit 0386b7f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions closql.el
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,28 @@
(key (oref-default obj closql-primary-key))
(id (closql--oref obj key))
(props (closql--slot-properties obj slot))
(table (alist-get :closql-table props)))
(table (alist-get :closql-table props))
(tables (alist-get :closql-tables props)))
(cond
((alist-get :closql-class props)
(error "Not implemented for closql-class slots: oset"))
((alist-get :closql-tables props)
(error "Not implemented for closql-tables slots: oset"))
(table
((or table (setq table (car tables)))
(closql-with-transaction db
(let ((columns (closql--table-columns db table)))
;; Caller might have modified value in place.
(closql--oset obj slot eieio--unbound)
(let ((list1 (closql-oref obj slot))
(list2 value)
elt1 elt2)
(when (length= columns 2)
(setq list1 (mapcar #'list list1))
(setq list2 (mapcar #'list list2)))
(cond (tables
(setq list1 (mapcar (lambda (e) (list (car e))) list1))
(setq list2 (mapcar (if (atom (car list2))
#'list
(lambda (e) (list (car e))))
list2)))
((length= columns 2)
(setq list1 (mapcar #'list list1))
(setq list2 (mapcar #'list list2))))
;; `list2' may not be sorted at all and `list1' has to
;; be sorted because Elisp and SQLite sort differently.
(setq list1 (cl-sort list1 #'string< :key #'car))
Expand Down

0 comments on commit 0386b7f

Please sign in to comment.