From b3a50358abf7f7d684b6c6652261235c1d2068f0 Mon Sep 17 00:00:00 2001 From: kimory Date: Tue, 18 Oct 2022 20:10:25 +0200 Subject: [PATCH] temp commit --- TODO.md | 3 ++- src/main.lisp | 41 +++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/TODO.md b/TODO.md index 85498a0..7e732fe 100644 --- a/TODO.md +++ b/TODO.md @@ -1,9 +1,10 @@ - Warning when indexes overlap (data add or update) - Data integrity on update (create temporary file with new data, rename old data file, move temporary file, remove old data file) - Handle errors (such as permissions) in an explicit way -- Grooming (create a consistent and convenient API) +- Grooming (create a consistent and convenient API, comments) - Improve data search - Check for TODOs - For indexes and partitions: check that the structure attribute exists. - Verify names of indexes and partitions: names are directly related to directory paths. - db/data-filepath instead of get-filepath. +- database -> db-path diff --git a/src/main.lisp b/src/main.lisp index 4511db5..8317f5b 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -77,13 +77,13 @@ (t (format nil "~A" object-attribute))))) (concatenate 'string dbpath "/partitions/by_" name "/" value "/"))) -; Example: database "name" object -> "./storage/cars/indexes/by_name/Corvet". +; Example: dbpath "name" #'vehicle-name object -> "./storage/cars/indexes/by_name/Corvet". (defun db/index/get-symlink-path (dbpath index-name fsymbol object) (concatenate 'string (db/index/get-directory-path dbpath index-name) (funcall fsymbol object))) -; Example: database "name" object "0000000015" +; Example: dbpath "name" #'vehicle-name object "0000000015" ; -> (osicat:make-link "./storage/cars/indexes/by_name/Corvet" ; :target "../../data/0000000015" ; :hard nil) @@ -98,7 +98,7 @@ (defun db/index/del (dbpath index-name fsymbol object) (delete-file (db/index/get-symlink-path dbpath index-name fsymbol object))) -; Example: database "color" object +; Example: dbpath "color" #'vehicle-color object ; -> "./storage/cars/partitions/by_color/Red/0000000015". (defun db/partition/get-symlink-path (dbpath partition-name fsymbol object file-name) (concatenate 'string @@ -108,7 +108,7 @@ ; example: "0000000015" file-name)) -; Example: database "color" object "0000000015" +; Example: dbpath "color" #'vehicle-color object "0000000015" ; -> (osicat:make-link "./storage/cars/partitions/by_color/Red/0000000015" ; :target "../../../data/0000000015" ; :hard nil) @@ -126,21 +126,22 @@ (defun db/partition/del (dbpath partition-name fsymbol object file-basename) (delete-file (db/partition/get-symlink-path dbpath partition-name fsymbol object file-basename))) -; example: db-path/indexes/by_name/ +; Example: db-path/indexes/by_name/ (defun db/new-index (database attribute-name fsymbol) - ; Create a directory for the indexes. - (ensure-directories-exist - (concatenate 'string (db-path database) "/indexes/by_" attribute-name "/")) - - ; Add this new index to the list. - (setf (gethash attribute-name (db-indexes database)) fsymbol) - - ; Generate index for all DB elements. - (maphash #'(lambda (number element) - (handler-case (db/index/new (db-path database) attribute-name fsymbol element (number->filename number)) - (OSICAT-POSIX:EEXIST () - (format t "db/new-index: symlink already exists, ignoring.~&")))) - (db-data database))) + (let ((dbpath (db-path database))) + ; create a directory for the indexes + (ensure-directories-exist + (concatenate 'string dbpath "/indexes/by_" attribute-name "/")) + + ; add this new index to the list + (setf (gethash attribute-name (db-indexes database)) fsymbol) + + ; generate index for all DB elements + (maphash #'(lambda (number object) + (handler-case (db/index/new dbpath attribute-name fsymbol object (number->filename number)) + (OSICAT-POSIX:EEXIST () + (format t "db/new-index: symlink already exists, ignoring.~&")))) + (db-data database)))) (defun db/partition/update (dbpath partition-name fsymbol object file-name old-object) (let ((new-value (funcall fsymbol object)) @@ -152,7 +153,7 @@ ; create new partition (db/partition/new dbpath partition-name fsymbol object file-name))))) -; example: db-path/partitions/by_color/ +; Example: db-path/partitions/by_color/ (defun db/new-partition (database attribute-name fsymbol) (let (dbpath (db-path database)) ; create a directory for the partitions @@ -173,7 +174,7 @@ (defun db/add/new-data-basename (database) (number->filename (db-current-index database))) -; Example: {db-path}/data/000000000000018 +; Example: {db-path}/data/000000000000018. (defun get-filepath (dbpath file-name) (concatenate 'string dbpath "/data/" file-name))