Simple database: Difference between revisions

Content added Content deleted
(Add emacs lisp)
mNo edit summary
Line 1,454: Line 1,454:
(switch-to-buffer "**content**")
(switch-to-buffer "**content**")
(end-of-buffer)
(end-of-buffer)
(insert (format "%s\n"
(let (row-data)
(append (list 'id (dbe-next-id)) (ensure-list row))))
(setq row-data (append (list 'id (dbe-next-id)) (ensure-list row)))
(insert (format "%s\n" row-data))
)
(message ">> Row added: %s" row-data) ) ) )
)


(defun dbe-find-by-id (row-id)
(defun dbe-find-by-id (row-id)
Line 1,463: Line 1,463:
(let (row-found)
(let (row-found)
(dbe-rows (lambda (row)
(dbe-rows (lambda (row)
;;(message " checking row: %s" row)
(when (equal (plist-get row 'id) row-id)
(when (equal (plist-get row 'id) row-id)
(setq row-found row)) )
(setq row-found row)) )
:continue (lambda () (null row-found)))
:continue (lambda () (null row-found)))
(message "row found: %s" row-found)
(message ">> Row found: %s" row-found)
)
)
Line 1,478: Line 1,477:
M-x dbe-insert
M-x dbe-insert
Please enter the row data in plist format: (name "book1" author "author1")
Please enter the row data in plist format: (name "book1" author "author1")
>> Row added: (id 1 name book1 author author1)


M-x dbe-insert
M-x dbe-insert
Please enter the row data in plist format: (name "book2" author "author2")
Please enter the row data in plist format: (name "book2" author "author2")
>> Row added: (id 2 name book2 author author2)


M-x dbe-find-by-id
M-x dbe-find-by-id
Please enter row id: 2
Please enter row id: 2
row found: (id 2 name book2 author author2)
>> Row found: (id 2 name book2 author author2)
</pre>
</pre>