From fe41a86eb8d25764d4bfa74585ad43e8379476d1 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Tue, 11 Oct 2022 23:20:35 +0200 Subject: [PATCH] Indexes (draft). --- src/dodb.cl | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/dodb.cl b/src/dodb.cl index f0f6edc..9969437 100755 --- a/src/dodb.cl +++ b/src/dodb.cl @@ -1,7 +1,7 @@ #!/usr/local/bin/clisp -; (load "~/.quicklisp/setup.lisp") -; (ql:quickload "osicat") +(load "~/.quicklisp/setup.lisp") +(ql:quickload "osicat") (load "./util.cl") (defpackage :dodb @@ -45,15 +45,41 @@ ; Add this new index to the list. (push attribute-name (db-indexes database))) +(defun to-upper-case (some-string) + (format nil "~@:(~a~)" some-string)) + +; Returns "Corvet". +(defun db/index/get-filename (database index-name object) + (funcall ; example: call function "VEHICLE-NAME" + (find-symbol (to-upper-case + (concatenate 'string (db-struct-name database) "-" index-name))) + object)) + +(defun db/add/new-link (database index-name object file-name) + (let ((symlink-path + (concatenate 'string + (db-path database) + "/by_" index-name "/" + (db/index/get-filename database index-name object)))) + + ; Works even when the database directory is moved. + (osicat:make-link symlink-path + :target (concatenate 'string "../data/" file-name) + :hard nil) + )) + (defun db/add (database object) -; (osicat:make-link "lien-symbolique" :target "data.dat" :hard nil) (incf (db-current-index database)) - (util:write-object-to-file object (concatenate 'string - (db-path database) - "/data/" - (format nil "~15,'0D.data" (db-current-index database)))) - ; TODO: handle indexes - ; TODO: handle partitions + (let ((file-name (format nil "~15,'0D.data" (db-current-index database)))) + (util:write-object-to-file object (concatenate 'string + (db-path database) "/data/" file-name)) + + ; TODO: handle indexes + (loop for index in (db-indexes database) + do (db/add/new-link database index object file-name)) + + ; TODO: handle partitions + ) ) ; test structure