object update: update the indexes
parent
284e3a951e
commit
ddb6d5b3ff
31
src/dodb.cl
31
src/dodb.cl
|
@ -106,17 +106,20 @@
|
|||
:hard nil)
|
||||
))
|
||||
|
||||
;(defun db/index/update (database index-name object file-name old-object)
|
||||
; (let* ((struct-name (db-struct-name database))
|
||||
; (new-value (get-object-attribute struct-name index-name object))
|
||||
; (old-value (get-object-attribute struct-name index-name old-object))
|
||||
; (symlink-path (db/index/get-symlink-path database index-name object)))
|
||||
; (if (not (equal new-value old-value))
|
||||
; ())))
|
||||
|
||||
(defun db/index/del (database index-name object)
|
||||
(delete-file (db/index/get-symlink-path database index-name object)))
|
||||
|
||||
(defun db/index/update (database index-name object file-name old-object)
|
||||
(let* ((struct-name (db-struct-name database))
|
||||
(new-value (get-object-attribute struct-name index-name object))
|
||||
(old-value (get-object-attribute struct-name index-name old-object)))
|
||||
(if (not (equal new-value old-value))
|
||||
(progn
|
||||
; delete old index
|
||||
(db/index/del database index-name old-object)
|
||||
; create new index
|
||||
(db/index/new database index-name object file-name)))))
|
||||
|
||||
; Example: database "color" object
|
||||
; -> "./storage/cars/partitions/by_color/Red/0000000015".
|
||||
(defun db/partition/get-symlink-path (database partition-name object file-name)
|
||||
|
@ -263,7 +266,7 @@
|
|||
; 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-basename (number->filename object-index))
|
||||
(file-path (get-filepath database file-basename))
|
||||
(old-object (util:read-object-from-file file-path))
|
||||
(tmp-file-basename (concatenate 'string file-basename "_tmp"))
|
||||
|
@ -272,14 +275,14 @@
|
|||
; write object to temporary file
|
||||
(util:write-object-to-file object tmp-file-path)
|
||||
|
||||
; TODO: either remove the file or read the documentation on rename-file
|
||||
(delete-file 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/update database index object file-basename old-object))
|
||||
(loop for index in (db-indexes database)
|
||||
do (db/index/update database index object file-basename old-object))
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -293,7 +296,9 @@
|
|||
|
||||
(defstruct vehicle name color)
|
||||
|
||||
(defparameter cars (db/new "vehicle" "./storage/cars/"))
|
||||
;(defparameter cars (db/new "vehicle" "./storage/cars/"))
|
||||
; to launch the tests in RAM
|
||||
(defparameter cars (db/new "vehicle" "/tmp/storage/cars/"))
|
||||
|
||||
(db/add cars (make-vehicle :name "Corvet" :color "Red"))
|
||||
(db/add cars (make-vehicle :name "Ferrari" :color "Red"))
|
||||
|
|
Loading…
Reference in New Issue