Indexes (draft).

draft
Karchnu 2022-10-11 23:20:35 +02:00
parent 20fec34dcc
commit fe41a86eb8
1 changed files with 35 additions and 9 deletions

View File

@ -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