db/add draft

draft
Karchnu 2022-10-11 20:44:38 +02:00
parent 1c9648e9a0
commit 20fec34dcc
1 changed files with 22 additions and 4 deletions

View File

@ -1,7 +1,9 @@
#!/usr/local/bin/clisp
(load "./util.cl")
; (load "~/.quicklisp/setup.lisp")
; (ql:quickload "osicat")
(load "./util.cl")
(defpackage :dodb
(:use :common-lisp :util)
; TODO
@ -28,17 +30,30 @@
; index = 1-1
; partition = 1-n
; String Path [String] [String]
(defstruct db struct-name path (indexes ()) (partitions ()))
; String Path [String] [String] Int
(defstruct db struct-name path (indexes ()) (partitions ()) (current-index 0))
(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))
; example: db-path/by_name/
(defun db/new-index (database attribute-name)
; Create a directory for the indexes.
(ensure-directories-exist
(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
@ -48,6 +63,9 @@
(setf cars (db/new "vehicle" "./storage/cars/"))
; (format t "~&~S~&" cars)
(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"))
; (db/get-by-index cars "name" "foo"))
; (setf cars_by_name (db/new-index cars "name" (optional: (lambda (x) (vehicle-name x)))))