Search is okay-ish.
This commit is contained in:
parent
3f1e8edf95
commit
16fb640d2f
62
src/dodb.cl
62
src/dodb.cl
@ -20,9 +20,9 @@
|
||||
(defun to-upper-case (some-string)
|
||||
(format nil "~@:(~a~)" some-string))
|
||||
|
||||
; Example: 18 -> 000000000000018.data
|
||||
; Example: 18 -> 000000000000018
|
||||
(defun number->filename (number)
|
||||
(format nil "~15,'0D.data" number))
|
||||
(format nil "~15,'0D" number))
|
||||
|
||||
; Example: "vehicle" "color" object -> (vehicle-color object) -> "Red"
|
||||
(defun get-object-attribute (struct-name attribute-name object)
|
||||
@ -46,7 +46,7 @@
|
||||
(ensure-directories-exist (concatenate 'string path "/data/"))
|
||||
(make-db :struct-name struct-name :path path))
|
||||
|
||||
; Example: ./storage/cars 18 -> ./storage/cars/data/000000000000018.data
|
||||
; Example: ./storage/cars 18 -> ./storage/cars/data/000000000000018
|
||||
; USAGE: when dealing with hash keys from the in-memory db.
|
||||
; The hash key is the number used to build the filename.
|
||||
(defun db/data-filepath (dbpath number)
|
||||
@ -70,9 +70,9 @@
|
||||
(db/index/get-directory-path database index-name)
|
||||
(db/index/get-filename database index-name object)))
|
||||
|
||||
; Example: database "name" object "0000000015.data"
|
||||
; Example: database "name" object "0000000015"
|
||||
; -> (ln "./storage/cars/indexes/by_name/Corvet"
|
||||
; :target "../../data/0000000015.data"
|
||||
; :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)))
|
||||
@ -84,18 +84,18 @@
|
||||
))
|
||||
|
||||
; Example: database "color" object
|
||||
; -> "./storage/cars/partitions/by_color/Red/0000000015.data".
|
||||
; -> "./storage/cars/partitions/by_color/Red/0000000015".
|
||||
(defun db/partition/get-symlink-path (database partition-name object file-name)
|
||||
(concatenate 'string
|
||||
(db/partition/get-directory-path database partition-name
|
||||
; example: "Red"
|
||||
(get-object-attribute (db-struct-name database) partition-name object))
|
||||
; example: "0000000015.data"
|
||||
; example: "0000000015"
|
||||
file-name))
|
||||
|
||||
; Example: database "color" object "0000000015.data"
|
||||
; -> (ln "./storage/cars/partitions/by_color/Red/0000000015.data"
|
||||
; :target "../../../data/0000000015.data"
|
||||
; Example: database "color" object "0000000015"
|
||||
; -> (ln "./storage/cars/partitions/by_color/Red/0000000015"
|
||||
; :target "../../../data/0000000015"
|
||||
; :hard nil)
|
||||
(defun db/partition/new (database partition-name object file-name)
|
||||
(let ((symlink-path
|
||||
@ -136,11 +136,11 @@
|
||||
(db/partition/new database attribute-name element (number->filename number)))
|
||||
(db-data database)))
|
||||
|
||||
; Example: database -> "000000000000018.data".
|
||||
; Example: database -> "000000000000018".
|
||||
(defun db/add/new-data-filename (database)
|
||||
(number->filename (db-current-index database)))
|
||||
|
||||
; Example: {db-path}/data/000000000000018.data
|
||||
; Example: {db-path}/data/000000000000018
|
||||
(defun db/add/new-data-filepath (database file-name)
|
||||
(concatenate 'string (db-path database) "/data/" file-name))
|
||||
|
||||
@ -165,14 +165,38 @@
|
||||
; database.data[database.current-index] = object
|
||||
(setf (gethash (db-current-index database) (db-data database)) object))
|
||||
|
||||
; TODO: should we search for the data from the FS or in-memory?
|
||||
(defun db/get-by-index (database index-name value)
|
||||
(util:read-object-from-file (concatenate 'string
|
||||
(db/index/get-directory-path database index-name) "/" value)))
|
||||
(alias basename pathname-name)
|
||||
|
||||
(defun db/get-by-partition (database name value)
|
||||
(loop for car in (ls (db/partition/get-directory-path database name value))
|
||||
collect (util:read-object-from-file car)))
|
||||
; Search for the data from the FS.
|
||||
; TODO: get the hash index, too.
|
||||
(defun db/search/fs/get-by-index (database index-name value)
|
||||
(parse-integer
|
||||
(basename
|
||||
(osicat:read-link
|
||||
(concatenate 'string
|
||||
(db/index/get-directory-path database index-name) "/" value)))))
|
||||
; (util:read-object-from-file (concatenate 'string
|
||||
; (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))
|
||||
collect (parse-integer (basename filename))))
|
||||
|
||||
;; Search for the data from the in-memory data.
|
||||
;; TODO: get the hash index, too.
|
||||
;
|
||||
;(defun db/search/mem/get-by-index (database index-name value)
|
||||
; (util:read-object-from-file (concatenate 'string
|
||||
; (db/index/get-directory-path database index-name) "/" value)))
|
||||
;
|
||||
;(defun db/search/mem/get-by-partition (database name value)
|
||||
; (loop for car in (ls (db/partition/get-directory-path database name value))
|
||||
; collect (util:read-object-from-file car)))
|
||||
|
||||
; 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)
|
||||
|
||||
;
|
||||
; TEST SCENARIO
|
||||
|
Loading…
Reference in New Issue
Block a user