X-Git-Url: https://git.jsancho.org/?p=bongodb.git;a=blobdiff_plain;f=src%2Fbongodb.scm;h=6fc16fe0fcfababa251b2e7686263640e2a2cd18;hp=e4df14bde9e1699503e91b4b9d6b9883446ba0b1;hb=07eed7138a1b4aecb9d8ae0926ba22dc82ebe94e;hpb=0fe9f925e00b6899f3b685082ed9b3374933c527 diff --git a/src/bongodb.scm b/src/bongodb.scm index e4df14b..6fc16fe 100644 --- a/src/bongodb.scm +++ b/src/bongodb.scm @@ -24,7 +24,10 @@ collection? count insert - find)) + find + $eq + $exists + $not)) ;;; Collection Definition @@ -75,7 +78,7 @@ (apply insert (cons newcol (cdr documents))) (values rescol (cons docid docids))))))) -(define (find col filter) +(define (find col . filter) "Query the collection and return the documents that match with filter" (let ((table (get-table col))) (vhash-fold @@ -93,10 +96,30 @@ #t) (else (and - (equal? (vhash-assoc (caar filter) document) (car filter)) + ((car filter) document) (match-document? document (cdr filter)))))) +;;; Queries + +(define ($eq field value) + (lambda (document) + (let ((stored (vhash-assoc field document))) + (and stored + (equal? (cdr stored) value))))) + + +(define ($exists field) + (lambda (document) + (and (vhash-assoc field document) + #t))) + + +(define ($not expr) + (lambda (document) + (not (expr document)))) + + ;;; Tools (define (vhash->alist vhash)