Aliases removed and search functions renamed

draft
kimory 2022-10-18 10:08:10 +02:00
parent d522a80f51
commit d1dc936eee
1 changed files with 9 additions and 20 deletions

View File

@ -14,15 +14,8 @@
))
(in-package dodb)
(defmacro alias (to fn)
`(setf (fdefinition ',to) #',fn))
(alias ln osicat:make-link)
(alias ls osicat:list-directory)
(alias basename pathname-name)
(defun filename->integer (filename)
(parse-integer (basename filename)))
(parse-integer (pathname-name filename))) ; pathname-name returns the basename
(defun to-upper-case (some-string)
(format nil "~@:(~a~)" some-string))
@ -58,7 +51,7 @@
(ensure-directories-exist data-dir-path)
(loop for filename in (ls data-dir-path)
(loop for filename in (osicat:list-directory data-dir-path)
do (let ((id (filename->integer filename))
(value (util:read-object-from-file filename)))
(if (> id current-index)
@ -107,14 +100,14 @@
(db/index/get-filename database index-name object)))
; Example: database "name" object "0000000015"
; -> (ln "./storage/cars/indexes/by_name/Corvet"
; -> (osicat:make-link "./storage/cars/indexes/by_name/Corvet"
; :target "../../data/0000000015"
; :hard nil)
(defun db/index/new (database index-name object file-name)
(let ((symlink-path (db/index/get-symlink-path database index-name object)))
; Works even when the database directory is moved.
(ln symlink-path
(osicat:make-link symlink-path
:target (concatenate 'string "../../data/" file-name)
:hard nil)
))
@ -133,7 +126,7 @@
file-name))
; Example: database "color" object "0000000015"
; -> (ln "./storage/cars/partitions/by_color/Red/0000000015"
; -> (osicat:make-link "./storage/cars/partitions/by_color/Red/0000000015"
; :target "../../../data/0000000015"
; :hard nil)
(defun db/partition/new (database partition-name object file-name)
@ -143,7 +136,7 @@
(ensure-directories-exist symlink-path)
; Works even when the database directory is moved.
(ln symlink-path
(osicat:make-link symlink-path
:target (concatenate 'string "../../../data/" file-name)
:hard nil)))
@ -243,7 +236,7 @@
(remhash object-index (db-data database))))
; Search for the data from the FS.
(defun db/search/fs/get-by-index (database index-name value)
(defun db/get-by-index (database index-name value)
(filename->integer
(osicat:read-link
(concatenate 'string
@ -252,14 +245,10 @@
; (db/index/get-directory-path database index-name) "/" value)))
; Search for the data from the FS.
(defun db/search/fs/get-by-partition (database name value)
(loop for filename in (ls (db/partition/get-directory-path database name value))
(defun db/get-by-partition (database name value)
(loop for filename in (osicat:list-directory (db/partition/get-directory-path database name value))
collect (filename->integer filename)))
; By default, search on the FS.
(alias db/get-by-index db/search/fs/get-by-index)
(alias db/get-by-partition db/search/fs/get-by-partition)
(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))