From 7821a1a819203a9cacbaa724fa52ae4f04d86163 Mon Sep 17 00:00:00 2001 From: kimory Date: Sun, 16 Oct 2022 23:16:41 +0200 Subject: [PATCH] Export more functions, db/add returns index, remove the scenario. --- src/dodb.cl | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/src/dodb.cl b/src/dodb.cl index ba7be37..a09f2f0 100644 --- a/src/dodb.cl +++ b/src/dodb.cl @@ -1,6 +1,6 @@ (ql:quickload "osicat") -(load "./util.cl") +; (load "./util.cl") (defpackage :dodb (:use :common-lisp :util) ; TODO @@ -8,6 +8,12 @@ :db/new ; new database :db/new-index ; symlinks based on an unique ID :db/new-partition ; symlinks based on a shared ID + :db/add ; add a new value in the DB + :db/update ; update a value in the DB + :db/del ; del a value from the DB + :db/get-by-index ; + :db/get-by-partition ; + :db-data ; )) (in-package dodb) @@ -209,7 +215,8 @@ ; store new in-memory data ; database.data[database.current-index] = object - (setf (gethash (db-current-index database) (db-data database)) object)) + (setf (gethash (db-current-index database) (db-data database)) object) + (db-current-index database)) (defun db/del (database object-index) (let ((file-basename (number->filename object-index)) @@ -286,35 +293,3 @@ ; handle partitions (loop for partition in (db-partitions database) do (db/partition/update database partition object file-basename old-object)))) - -; -; TEST SCENARIO -; - -(defstruct vehicle name color) - -;(defparameter cars (db/new "vehicle" "./storage/cars/")) -; to launch the tests in RAM -(defparameter cars (db/new "vehicle" "/tmp/storage/cars/")) - -(db/add cars (make-vehicle :name "Corvet" :color "Red")) -(db/add cars (make-vehicle :name "Ferrari" :color "Red")) -(db/add cars (make-vehicle :name "Deudeuch" :color "Beige")) -(db/add cars (make-vehicle :name "BMW" :color "Blue")) -(db/add cars (make-vehicle :name "Suzuki Wagon" :color "Blue")) - -(db/new-index cars "name") -(db/new-partition cars "color") - - -(format t "~&~S~&" cars) - -(format t "db/get-by-index ~S~&" (db/get-by-index cars "name" "Corvet")) -(format t "db/get-by-partition red cars:~&") - -(loop for car in (db/get-by-partition cars "color" "Red") - do (format t "- ~S~&" car)) - -(let ((suzuki (db/get-by-index cars "name" "Suzuki Wagon"))) - (setf (vehicle-color (gethash suzuki (db-data cars))) "White") - (db/update cars suzuki))