Created
December 26, 2011 20:39
-
-
Save outworlder/1522080 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(foreign-declare "#include <mongo.h>") | |
(define-foreign-type Mongo c-pointer) | |
(define mongo-create | |
(foreign-lambda* c-pointer () | |
"mongo* mongo; | |
mongo = malloc(sizeof(mongo)); | |
C_return(mongo);")) | |
(define mongo-init | |
(foreign-lambda void "mongo_init" Mongo)) | |
(define mongo-connect | |
(foreign-lambda int "mongo_connect" Mongo c-string int)) | |
;;; TODO: Test | |
(define mongo-replset-init | |
(foreign-lambda void "mongo_replset_init" Mongo c-string)) | |
(define mongo-replset-add-seed | |
(foreign-lambda void "mongo_replset_add_seed" Mongo c-string int)) | |
;;; mongo_parse_host is unecessary | |
(define mongo-replset-connect | |
(foreign-lambda int "mongo_replset_connect" Mongo)) | |
(define mongo-set-op-timeout | |
(foreign-lambda int "mongo_set_op_timeout" Mongo int)) | |
;;; Higher-level functions | |
(define (mongo-init!) | |
(let ([mongo (mongo-create)]) | |
(mongo-init mongo) | |
(make-parameter mongo))) | |
(define *conn* (mongo-init!)) | |
(display (mongo-connect (*conn*) "127.0.0.1" 27017)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment