Update (draft)

draft
Philippe PITTOLI 2022-10-14 18:14:24 +02:00
parent 94d522e778
commit 25239281b7
1 changed files with 30 additions and 4 deletions

View File

@ -250,10 +250,30 @@
(alias db/get-by-index db/search/fs/get-by-index)
(alias db/get-by-partition db/search/fs/get-by-partition)
;(defun db/update (database object-index)
; (let ((object (gethash object-index (db-data database))))
; ; TODO: write the object on the FS
; ))
; TODO: remove old indexes and partitions
; TODO: check database integrity (redundancy)
; TODO: locking
(defun db/update (database object-index)
(let* ((object (gethash object-index (db-data database)))
(file-basename (db/add/new-data-basename database))
(file-path (get-filepath database file-basename))
(old-object (util:read-object-from-file file-path))
(tmp-file-basename (concatenate 'string file-basename "_tmp"))
(tmp-file-path (get-filepath database tmp-file-basename)))
; write object to temporary file
(util:write-object-to-file object tmp-file-path)
; rename the temporary file
(rename-file tmp-file-path file-basename)
; handle indexes
(loop for index in (db-indexes database)
do (db/index/new database index object file-basename))
; handle partitions
(loop for partition in (db-partitions database)
do (db/partition/new database partition object file-basename))))
;
; TEST SCENARIO
@ -272,9 +292,15 @@
(db/new-index cars "name")
(db/new-partition cars "color")
(format t "~&~S~&" cars)
(format t "db/get-by-index ~S~&" (db/get-by-index cars "name" "Corvet"))
(format t "db/get-by-partition red cars:~&")
(loop for car in (db/get-by-partition cars "color" "Red")
do (format t "- ~S~&" car))
(let ((suzuki (db/get-by-index cars "name" "Suzuki Wagon")))
(setf (vehicle-color (gethash suzuki (db-data cars))) "White")
(db/update cars suzuki))