Very early draft.

draft
Karchnu 2022-10-10 17:03:53 +02:00
parent e0a5fb7819
commit 069b879b36
2 changed files with 53 additions and 0 deletions

25
src/dodb.cl Normal file
View File

@ -0,0 +1,25 @@
(defpackage :dodb
(:use :common-lisp :util)
; TODO
(:export
:db/new ; new database
:db/new-index ; symlinks based on an unique ID
:db/new-partition ; symlinks based on a shared ID
))
(in-package dodb)
; TODO: equivalent in Crystal
; cars = DODB::DataBase(Car).new "./storage"
; cars_by_name = cars.new_index "name", &.name
; cars_by_name.get "foo"
; cars_by_name.update "blah", new-car
; cars_by_name.delete "blah"
;
; car = Car.new "Mustang", "red", [] of String
; cars_by_name.update_or_create car.name, car
; TODO
; (setf cars (db/new :structure car :directory "./storage"))
; (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)))))

28
src/util.cl Normal file
View File

@ -0,0 +1,28 @@
; (make-package :ut)
; (in-package :ut)
(defpackage :util
(:use :common-lisp)
(:nicknames :ut)
(:export :write-object-to-file
:read-file
:read-object-from-file))
(in-package util)
(defun read-file (infile)
(with-open-file (instream infile
:direction :input
:if-does-not-exist nil)
(when instream
(let ((string (make-string (file-length instream))))
(read-sequence string instream)
string))))
(defun read-object-from-file (infile)
(read-from-string (read-file infile)))
(defun write-object-to-file (object outfile)
(with-open-file (my-file outfile
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(format my-file "~&~S~&" object)))