diff --git a/src/dodb.cl b/src/dodb.cl index e7e588b..f52da9d 100644 --- a/src/dodb.cl +++ b/src/dodb.cl @@ -49,14 +49,26 @@ ; db/new ensures directory '/data/' exist, ; then loads values from existing files, if any, and puts them into db-data. (defun db/new (struct-name path) - (ensure-directories-exist (concatenate 'string path "/data/")) + (let ((data (make-hash-table)) + (data-dir-path (concatenate 'string path "/data/")) + (current-index 0)) - (let ((data (make-hash-table))) - (loop for filename in (ls (concatenate 'string path "/data/")) + (ensure-directories-exist data-dir-path) + + (loop for filename in (ls data-dir-path) do (let ((id (filename->integer filename)) (value (util:read-object-from-file filename))) + (if (> id current-index) + (setf current-index id)) (setf (gethash id data) value))) - (make-db :struct-name struct-name :path path :data data))) + + (format t "Max current index: ~A~&" current-index) + + (make-db + :struct-name struct-name + :path path + :data data + :current-index current-index))) ; Example: ./storage/cars 18 -> ./storage/cars/data/000000000000018