Current-index is being taken care of.
parent
b7abc32ec0
commit
47a50e981a
20
src/dodb.cl
20
src/dodb.cl
|
@ -49,14 +49,26 @@
|
||||||
; db/new ensures directory '<path>/data/' exist,
|
; db/new ensures directory '<path>/data/' exist,
|
||||||
; then loads values from existing files, if any, and puts them into db-data.
|
; then loads values from existing files, if any, and puts them into db-data.
|
||||||
(defun db/new (struct-name path)
|
(defun db/new (struct-name path)
|
||||||
(ensure-directories-exist (concatenate 'string path "/data/"))
|
(let ((data (make-hash-table))
|
||||||
|
(data-dir-path (concatenate 'string path "/data/"))
|
||||||
|
(current-index 0))
|
||||||
|
|
||||||
(let ((data (make-hash-table)))
|
(ensure-directories-exist data-dir-path)
|
||||||
(loop for filename in (ls (concatenate 'string path "/data/"))
|
|
||||||
|
(loop for filename in (ls data-dir-path)
|
||||||
do (let ((id (filename->integer filename))
|
do (let ((id (filename->integer filename))
|
||||||
(value (util:read-object-from-file filename)))
|
(value (util:read-object-from-file filename)))
|
||||||
|
(if (> id current-index)
|
||||||
|
(setf current-index id))
|
||||||
(setf (gethash id data) value)))
|
(setf (gethash id data) value)))
|
||||||
(make-db :struct-name struct-name :path path :data data)))
|
|
||||||
|
(format t "Max current index: ~A~&" current-index)
|
||||||
|
|
||||||
|
(make-db
|
||||||
|
:struct-name struct-name
|
||||||
|
:path path
|
||||||
|
:data data
|
||||||
|
:current-index current-index)))
|
||||||
|
|
||||||
|
|
||||||
; Example: ./storage/cars 18 -> ./storage/cars/data/000000000000018
|
; Example: ./storage/cars 18 -> ./storage/cars/data/000000000000018
|
||||||
|
|
Loading…
Reference in New Issue