X-Git-Url: https://git.jsancho.org/?p=bongodb.git;a=blobdiff_plain;f=src%2Fbongodb.scm;h=3cffa48d5ce6f7280958a00d1abf04ece8acc50b;hp=c6b2571605ba23e3a9b4e1ef64a5796ea57760ba;hb=9799d66d7e1538bbe2a672946ce80b49dc55ca84;hpb=845c98271c1c4e10200ea0d15f6cafabb52d3ea9 diff --git a/src/bongodb.scm b/src/bongodb.scm index c6b2571..3cffa48 100644 --- a/src/bongodb.scm +++ b/src/bongodb.scm @@ -1,4 +1,3 @@ -;;; ;;; BongoDB, an embedded document-based engine ;;; Copyright (C) 2016 by Javier Sancho Fernandez ;;; @@ -20,7 +19,12 @@ #:use-module (ice-9 receive) #:use-module (ice-9 vlist) #:use-module (srfi srfi-9) - #:use-module (srfi srfi-9 gnu)) + #:use-module (srfi srfi-9 gnu) + #:export (make-collection + collection? + count + insert + find)) ;;; Collection Definition @@ -33,11 +37,14 @@ (define (make-collection) (make-collection-record vlist-null)) +(define (count col) + (vlist-length (get-table col))) + (set-record-type-printer! collection (lambda (record port) (format port "#" - (vlist-length (get-table record))))) + (count record)))) ;;; Working with documents @@ -84,13 +91,3 @@ (lambda (key value result) (assoc-set! result key value)) '() vhash)) - - -;;; Testing - -(define (sample-test) - (let ((col (make-collection))) - (format #t "1 New collection: ~a~%" col) - (set! col (insert col '((a . 1) (b . 2)) '((a . 10) (b . 20)) '((a . 1) (b . "hello world")))) - (format #t "2 Insert 3 documents: ~a~%" col) - (format #t "3 Search (a . 1): ~a~%" (find col '((a . 1))))))