4 ORM Operations
(require db/mongodb/orm/main) | package: mongodb |
An "ORM" style API is built on the basic Mongo operations.
4.1 Dictionaries
(require db/mongodb/orm/dict) | package: mongodb |
A Mongo dictionary is a dictionary backed by Mongo.
procedure
(create-mongo-dict col) → mongo-dict?
col : string?
procedure
(mongo-dict-query col query) → (sequenceof mongo-dict?)
col : string? query : bson-document/c
procedure
(mongo-dict? x) → boolean?
x : any/c
parameter
(current-mongo-db) → (or/c false/c mongo-db?)
(current-mongo-db db) → void? db : (or/c false/c mongo-db?)
procedure
(mongo-dict-ref md key [fail]) → any/c
md : mongo-dict? key : symbol? fail : any/c = bson-null
procedure
(mongo-dict-set! md key val) → void
md : mongo-dict? key : symbol? val : any/c
procedure
(mongo-dict-remove! md key) → void
md : mongo-dict? key : symbol?
procedure
md : mongo-dict?
procedure
(mongo-dict-inc! md key [amt]) → void
md : mongo-dict? key : symbol? amt : number? = 1
procedure
(mongo-dict-push! md key val) → void
md : mongo-dict? key : symbol? val : any/c
procedure
(mongo-dict-append! md key vals) → void
md : mongo-dict? key : symbol? vals : sequence?
procedure
(mongo-dict-set-add! md key val) → void
md : mongo-dict? key : symbol? val : any/c
procedure
(mongo-dict-set-add*! md key vals) → void
md : mongo-dict? key : symbol? vals : sequence?
procedure
(mongo-dict-pop! md key) → void
md : mongo-dict? key : symbol?
procedure
(mongo-dict-shift! md key) → void
md : mongo-dict? key : symbol?
procedure
(mongo-dict-pull! md key val) → void
md : mongo-dict? key : symbol? val : any/c
procedure
(mongo-dict-pull*! md key vals) → void
md : mongo-dict? key : symbol? vals : sequence?
4.2 Structures
(require db/mongodb/orm/struct) | package: mongodb |
define-mongo-struct is a macro to create some convenience functions for Mongo dictionaries.
syntax
(define-mongo-struct struct collection ([field opt ...] ...))
opt = #:required | #:immutable | #:ref | #:set! | #:inc | #:null | #:push | #:append | #:set-add | #:set-add* | #:pop | #:shift | #:pull | #:pull*
struct : identifier?
collection : string?
field : identifier?
Every field implicitly has the #:ref option. Every mutable field implicitly has the #:set! option. Every immutable field implicitly has the #:required option. It is an error for an immutable field to have any options other than #:required and #:ref, which are both implicit.
make-struct takes one keyword argument per field. If the field does not have the #:required option, the argument is optional and the instance will not contain a value for the field. make-struct returns a mongo-dict?.
If a field has the #:ref option, then struct-field is defined. It is implemented with mongo-dict-ref.
If a field has the #:set option, then set-struct-field! is defined. It is implemented with mongo-dict-set!.
If a field has the #:inc option, then inc-struct-field! is defined. It is implemented with mongo-dict-inc!.
If a field has the #:null option, then null-struct-field! is defined. It is implemented with mongo-dict-remove!.
If a field has the #:push option, then push-struct-field! is defined. It is implemented with mongo-dict-push!.
If a field has the #:append option, then append-struct-field! is defined. It is implemented with mongo-dict-append!.
If a field has the #:set-add option, then set-add-struct-field! is defined. It is implemented with mongo-dict-set-add!.
If a field has the #:set-add* option, then set-add*-struct-field! is defined. It is implemented with mongo-dict-set-add*!.
If a field has the #:pop option, then pop-struct-field! is defined. It is implemented with mongo-dict-pop!.
If a field has the #:shift option, then shift-struct-field! is defined. It is implemented with mongo-dict-shift!.
If a field has the #:pull option, then pull-struct-field! is defined. It is implemented with mongo-dict-pull!.
If a field has the #:pull* option, then pull*-struct-field! is defined. It is implemented with mongo-dict-pull*!.