db/new & db/index (draft) + example code
This commit is contained in:
parent
069b879b36
commit
1c9648e9a0
32
src/dodb.cl
Normal file → Executable file
32
src/dodb.cl
Normal file → Executable file
@ -1,3 +1,7 @@
|
||||
#!/usr/local/bin/clisp
|
||||
|
||||
(load "./util.cl")
|
||||
|
||||
(defpackage :dodb
|
||||
(:use :common-lisp :util)
|
||||
; TODO
|
||||
@ -18,8 +22,32 @@
|
||||
; 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
|
||||
; partition = 1-n
|
||||
; String Path [String] [String]
|
||||
(defstruct db struct-name path (indexes ()) (partitions ()))
|
||||
|
||||
(defun db/new (struct-name path)
|
||||
(ensure-directories-exist path)
|
||||
(make-db :struct-name struct-name :path path))
|
||||
|
||||
; example: db-path/by_name/
|
||||
(defun db/new-index (database attribute-name)
|
||||
(ensure-directories-exist
|
||||
(concatenate 'string (db-path database) "/by_" attribute-name "/"))
|
||||
)
|
||||
|
||||
; test structure
|
||||
(defstruct vehicle name color)
|
||||
|
||||
; TODO
|
||||
; (setf cars (db/new :structure car :directory "./storage"))
|
||||
(setf cars (db/new "vehicle" "./storage/cars/"))
|
||||
; (format t "~&~S~&" cars)
|
||||
(db/new-index cars "name")
|
||||
; (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) (car-name x)))))
|
||||
; (setf cars_by_name (db/new-index cars "name" (optional: (lambda (x) (vehicle-name x)))))
|
||||
|
Loading…
Reference in New Issue
Block a user