Grooming.
parent
49e155248a
commit
5624c7b7ee
68
src/dodb.cl
68
src/dodb.cl
|
@ -11,33 +11,12 @@
|
||||||
))
|
))
|
||||||
(in-package dodb)
|
(in-package dodb)
|
||||||
|
|
||||||
;(defun ln (path &key target hard)
|
|
||||||
; (format t "LN: ~A -> ~A~&" path target))
|
|
||||||
;(defun ls (path)
|
|
||||||
; (format t "LS: ~A~&" path target))
|
|
||||||
; (osicat:make-link symlink-path
|
|
||||||
; :target (concatenate 'string "../../data/" file-name)
|
|
||||||
; :hard nil))
|
|
||||||
|
|
||||||
(defmacro alias (to fn)
|
(defmacro alias (to fn)
|
||||||
`(setf (fdefinition ',to) #',fn))
|
`(setf (fdefinition ',to) #',fn))
|
||||||
|
|
||||||
(alias ln osicat:make-link)
|
(alias ln osicat:make-link)
|
||||||
(alias ls osicat:list-directory)
|
(alias ls osicat:list-directory)
|
||||||
|
|
||||||
; TODO: equivalent in Crystal
|
|
||||||
; cars = DODB::DataBase(Car).new "./storage"
|
|
||||||
; cars_by_name = cars.new_index "name", &.name
|
|
||||||
; cars_by_name.get "foo"
|
|
||||||
; cars_by_name.update "blah", new-car
|
|
||||||
; cars_by_name.delete "blah"
|
|
||||||
;
|
|
||||||
; car = Car.new "Mustang", "red", [] of String
|
|
||||||
; cars_by_name.update_or_create car.name, car
|
|
||||||
|
|
||||||
|
|
||||||
; (defstruct index name func)
|
|
||||||
; index "name" (lambda (x) (car-name x))
|
|
||||||
|
|
||||||
; index = 1-1
|
; index = 1-1
|
||||||
; partition = 1-n
|
; partition = 1-n
|
||||||
; String Path [String] [String] Int
|
; String Path [String] [String] Int
|
||||||
|
@ -108,8 +87,7 @@
|
||||||
; example: "Red"
|
; example: "Red"
|
||||||
(get-object-attribute database partition-name object))
|
(get-object-attribute database partition-name object))
|
||||||
; example: "000000000000018.data"
|
; example: "000000000000018.data"
|
||||||
file-name
|
file-name))
|
||||||
))
|
|
||||||
|
|
||||||
(defun db/partition/new (database partition-name object file-name)
|
(defun db/partition/new (database partition-name object file-name)
|
||||||
(let ((symlink-path
|
(let ((symlink-path
|
||||||
|
@ -120,8 +98,7 @@
|
||||||
; Works even when the database directory is moved.
|
; Works even when the database directory is moved.
|
||||||
(ln symlink-path
|
(ln symlink-path
|
||||||
:target (concatenate 'string "../../../data/" file-name)
|
:target (concatenate 'string "../../../data/" file-name)
|
||||||
:hard nil)
|
:hard nil)))
|
||||||
))
|
|
||||||
|
|
||||||
; Example: 000000000000018.data
|
; Example: 000000000000018.data
|
||||||
(defun db/add/new-data-filename (database)
|
(defun db/add/new-data-filename (database)
|
||||||
|
@ -144,14 +121,24 @@
|
||||||
|
|
||||||
; handle partitions
|
; handle partitions
|
||||||
(loop for partition in (db-partitions database)
|
(loop for partition in (db-partitions database)
|
||||||
do (db/partition/new database partition object file-name))
|
do (db/partition/new database partition object file-name)))
|
||||||
)
|
|
||||||
|
|
||||||
; store new in-memory data
|
; store new in-memory data
|
||||||
(setf (gethash (db-current-index database) (db-data database)) 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)))
|
||||||
|
|
||||||
|
(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)))
|
||||||
|
|
||||||
|
;
|
||||||
|
; TEST SCENARIO
|
||||||
|
;
|
||||||
|
|
||||||
; test structure
|
|
||||||
(defstruct vehicle name color)
|
(defstruct vehicle name color)
|
||||||
|
|
||||||
(defparameter cars (db/new "vehicle" "./storage/cars/"))
|
(defparameter cars (db/new "vehicle" "./storage/cars/"))
|
||||||
|
@ -164,24 +151,7 @@
|
||||||
|
|
||||||
(format t "~&~S~&" cars)
|
(format t "~&~S~&" cars)
|
||||||
|
|
||||||
(defun db/get-by-index (database index-name value)
|
|
||||||
; (format t "db/get-by-index ~A => ~A" index-name value)
|
|
||||||
; TODO: should we search for the data from the FS or in-memory?
|
|
||||||
; (ls (db/index/get-directory-path database index-name))
|
|
||||||
(util:read-object-from-file (concatenate 'string
|
|
||||||
(db/index/get-directory-path database index-name) "/" value)))
|
|
||||||
|
|
||||||
(defun db/get-by-partition (database name value)
|
|
||||||
; (format t "db/get-by-partition ~A => ~A" name value)
|
|
||||||
;(ls (db/partition/get-directory-path database name value)))
|
|
||||||
(loop for car in (ls (db/partition/get-directory-path database name value))
|
|
||||||
collect (util:read-object-from-file car)))
|
|
||||||
|
|
||||||
(format t "db/get-by-index ~S~&" (db/get-by-index cars "name" "Corvet"))
|
(format t "db/get-by-index ~S~&" (db/get-by-index cars "name" "Corvet"))
|
||||||
(format t "db/get-by-partition red cars:~&")
|
(format t "db/get-by-partition red cars:~&")
|
||||||
(loop for car in (db/get-by-partition cars "color" "Red")
|
(loop for car in (db/get-by-partition cars "color" "Red")
|
||||||
do (format t "- ~S~&" car))
|
do (format t "- ~S~&" car))
|
||||||
|
|
||||||
; (setf cars_by_name (db/new-index cars "name"))
|
|
||||||
; (db/get-by-index cars "name" "foo"))
|
|
||||||
; (setf cars_by_name (db/new-index cars "name" (optional: (lambda (x) (vehicle-name x)))))
|
|
||||||
|
|
Loading…
Reference in New Issue