From 25239281b7648bc0d9cce1a7e8acf6e195e91756 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Fri, 14 Oct 2022 18:14:24 +0200 Subject: [PATCH] Update (draft) --- src/dodb.cl | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/dodb.cl b/src/dodb.cl index e05602b..deaf845 100644 --- a/src/dodb.cl +++ b/src/dodb.cl @@ -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))