Export more functions, db/add returns index, remove the scenario.

This commit is contained in:
kimory 2022-10-16 23:16:41 +02:00
parent 751e0efdec
commit 7821a1a819

View File

@ -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))