summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2021-01-12 09:14:06 +0100
committerpukkamustard <pukkamustard@posteo.net>2021-01-12 09:14:06 +0100
commitd4f99186a3f5d9d66b1d6d12d74c9bc8f66c33ad (patch)
tree09639f93815a790a84345c9a1eb84213d40fbe5c
parent82b569ec39389e799ffc7c9cf3da2ef92dfe39e3 (diff)
(lmdb low-level): Allow flags and name to mdb-dbi-open
-rw-r--r--lmdb/low-level.scm36
1 files changed, 32 insertions, 4 deletions
diff --git a/lmdb/low-level.scm b/lmdb/low-level.scm
index 99c5c43..e691a8b 100644
--- a/lmdb/low-level.scm
+++ b/lmdb/low-level.scm
@@ -65,6 +65,14 @@
mdb-dbi?
mdb-dbi-open
+ MDB_REVERSEKEY
+ MDB_DUPSORT
+ MDB_INTEGERKEY
+ MDB_DUPFIXED
+ MDB_INTEGERDUP
+ MDB_REVERSEDUP
+ MDB_CREATE
+
<mdb-val>
mdb-val?
make-mdb-val
@@ -240,7 +248,7 @@
;; MDB_dbi
-(define (mdb-dbi-open txn)
+(define* (mdb-dbi-open txn #:key (name #f) (flags 0))
(let* ((proc (liblmdb-func "mdb_dbi_open"
(list
;; MDB_txn* txn
@@ -251,18 +259,38 @@
unsigned-int
;; MDB_dbi* dbi
'*)))
+
+ ;; pointer to database name
+ (name-ptr (if (string? name)
+ (string->pointer name)
+ ;; else use NULL pointer
+ (make-pointer 0)))
+
+ ;; allocate pointer for dbi
(dbi-ptr (bytevector->pointer
(make-bytevector (sizeof '*))))
+
+ ;; call mdb_dbi_open
(return-value (proc (unwrap-mdb-txn txn)
- ;; null pointer TODO allow specifying name
- (make-pointer 0)
- 0
+ name-ptr
+ flags
dbi-ptr)))
+
(if (eqv? return-value MDB_SUCCESS)
;; dbi is an unsigned integer
(pointer-address (dereference-pointer dbi-ptr))
return-value)))
+;; Database flags
+
+(define MDB_REVERSEKEY #x02)
+(define MDB_DUPSORT #x04)
+(define MDB_INTEGERKEY #x08)
+(define MDB_DUPFIXED #x10)
+(define MDB_INTEGERDUP #x20)
+(define MDB_REVERSEDUP #x40)
+(define MDB_CREATE #x40000)
+
;; MDB_val
(define-wrapped-pointer-type <mdb-val>