diff --git a/src/dodb.cl b/src/dodb.cl new file mode 100644 index 0000000..738b5ef --- /dev/null +++ b/src/dodb.cl @@ -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))))) diff --git a/src/util.cl b/src/util.cl new file mode 100644 index 0000000..40332d3 --- /dev/null +++ b/src/util.cl @@ -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)))