db/add draft
parent
1c9648e9a0
commit
20fec34dcc
26
src/dodb.cl
26
src/dodb.cl
|
@ -1,7 +1,9 @@
|
||||||
#!/usr/local/bin/clisp
|
#!/usr/local/bin/clisp
|
||||||
|
|
||||||
(load "./util.cl")
|
; (load "~/.quicklisp/setup.lisp")
|
||||||
|
; (ql:quickload "osicat")
|
||||||
|
|
||||||
|
(load "./util.cl")
|
||||||
(defpackage :dodb
|
(defpackage :dodb
|
||||||
(:use :common-lisp :util)
|
(:use :common-lisp :util)
|
||||||
; TODO
|
; TODO
|
||||||
|
@ -28,17 +30,30 @@
|
||||||
|
|
||||||
; index = 1-1
|
; index = 1-1
|
||||||
; partition = 1-n
|
; partition = 1-n
|
||||||
; String Path [String] [String]
|
; String Path [String] [String] Int
|
||||||
(defstruct db struct-name path (indexes ()) (partitions ()))
|
(defstruct db struct-name path (indexes ()) (partitions ()) (current-index 0))
|
||||||
|
|
||||||
(defun db/new (struct-name path)
|
(defun db/new (struct-name path)
|
||||||
(ensure-directories-exist path)
|
(ensure-directories-exist (concatenate 'string path "/data/"))
|
||||||
(make-db :struct-name struct-name :path path))
|
(make-db :struct-name struct-name :path path))
|
||||||
|
|
||||||
; example: db-path/by_name/
|
; example: db-path/by_name/
|
||||||
(defun db/new-index (database attribute-name)
|
(defun db/new-index (database attribute-name)
|
||||||
|
; Create a directory for the indexes.
|
||||||
(ensure-directories-exist
|
(ensure-directories-exist
|
||||||
(concatenate 'string (db-path database) "/by_" attribute-name "/"))
|
(concatenate 'string (db-path database) "/by_" attribute-name "/"))
|
||||||
|
; Add this new index to the list.
|
||||||
|
(push attribute-name (db-indexes database)))
|
||||||
|
|
||||||
|
(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
|
||||||
)
|
)
|
||||||
|
|
||||||
; test structure
|
; test structure
|
||||||
|
@ -48,6 +63,9 @@
|
||||||
(setf cars (db/new "vehicle" "./storage/cars/"))
|
(setf cars (db/new "vehicle" "./storage/cars/"))
|
||||||
; (format t "~&~S~&" cars)
|
; (format t "~&~S~&" cars)
|
||||||
(db/new-index cars "name")
|
(db/new-index cars "name")
|
||||||
|
(db/add cars (make-vehicle :name "Corvet" :color "Red"))
|
||||||
|
(format t "~&~S~&" cars)
|
||||||
|
|
||||||
; (setf cars_by_name (db/new-index cars "name"))
|
; (setf cars_by_name (db/new-index cars "name"))
|
||||||
; (db/get-by-index cars "name" "foo"))
|
; (db/get-by-index cars "name" "foo"))
|
||||||
; (setf cars_by_name (db/new-index cars "name" (optional: (lambda (x) (vehicle-name x)))))
|
; (setf cars_by_name (db/new-index cars "name" (optional: (lambda (x) (vehicle-name x)))))
|
||||||
|
|
Loading…
Reference in New Issue