From 9c110610aef9763a498573f376ec24cfd51fe682 Mon Sep 17 00:00:00 2001 From: kimory Date: Tue, 18 Oct 2022 22:36:30 +0200 Subject: [PATCH] value->string --- src/main.lisp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/main.lisp b/src/main.lisp index f1478cb..1ebedae 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -24,6 +24,12 @@ (defun number->filename (number) (format nil "~15,'0D" number)) +(defun value->string (value) + (typecase value + (string value) + (symbol (symbol-name value)) + (t (format nil "~A" value)))) + ; index = 1-1 ; partition = 1-n (defstruct db @@ -66,19 +72,13 @@ ; Example: returns "./storage/cars/partitions/by_color/Red/". (defun db/partition/get-directory-path (dbpath name object-attribute) - (let ((value (typecase object-attribute - (string object-attribute) - (symbol (symbol-name object-attribute)) - (t (format nil "~A" object-attribute))))) - (concatenate 'string dbpath "/partitions/by_" name "/" value "/"))) + (let ((value (value->string object-attribute))) + (concatenate 'string dbpath "/partitions/by_" name "/" value "/"))) ; Example: "./storage/cars/" "name" #'vehicle-name object -> "./storage/cars/indexes/by_name/Corvet". (defun db/index/get-symlink-path (dbpath index-name fsymbol object) (let* ((value (funcall fsymbol object)) - (symlink-basename (typecase value - (string value) - (symbol (symbol-name value)) - (t (format nil "~A" value))))) + (symlink-basename (value->string value))) (concatenate 'string (db/index/get-directory-path dbpath index-name) symlink-basename))) @@ -225,10 +225,7 @@ ; Search for the data from the FS. (defun db/get-by-index (database index-name attribute-value) - (let ((value (typecase attribute-value - (string attribute-value) - (symbol (symbol-name attribute-value)) - (t (format nil "~A" attribute-value))))) + (let ((value (value->string attribute-value))) (filename->integer (osicat:read-link (concatenate 'string @@ -236,10 +233,7 @@ ; Search for the data from the FS. (defun db/get-by-partition (database name attribute-value) - (let ((value (typecase attribute-value - (string attribute-value) - (symbol (symbol-name attribute-value)) - (t (format nil "~A" attribute-value)))) + (let ((value (value->string attribute-value)) (dbpath (db-path database))) (loop for filename in (osicat:list-directory (db/partition/get-directory-path dbpath name value)) collect (filename->integer filename))))