From 1c9648e9a0d8e99197d24719da79e65cffeebd3a Mon Sep 17 00:00:00 2001 From: Karchnu Date: Mon, 10 Oct 2022 22:44:00 +0200 Subject: [PATCH] db/new & db/index (draft) + example code --- src/dodb.cl | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/dodb.cl diff --git a/src/dodb.cl b/src/dodb.cl old mode 100644 new mode 100755 index 738b5ef..4d1c134 --- a/src/dodb.cl +++ b/src/dodb.cl @@ -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)))))