lmdb

Check-in [ecd5bf87c6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Formatting tweaks
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | v1.0.0
Files: files | file ages | folders
SHA3-256: ecd5bf87c6683c9c6dcd444cbcc887e41429b960e22ebe5c66c52314caccfdfc
User & Date: murphy 2018-09-01 16:30:32
Context
2018-09-01
16:36
Added release information file check-in: 19c956667d user: murphy tags: trunk
16:30
Formatting tweaks check-in: ecd5bf87c6 user: murphy tags: trunk, v1.0.0
16:02
#:limit support for database-fold and friends check-in: d4ff8cd366 user: murphy tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lmdb.egg.

8
9
10
11
12
13
14
15
 (test-dependencies
   test)
 (components
   (extension lmdb
     (custom-build "build-lmdb")
     (source-dependencies "lmdb.h" "mdb.impl.c" "midl.h" "midl.impl.c"))))

;; vim: set ai et ts=8 sts=2 sw=2 ft=scheme: ;;







|
8
9
10
11
12
13
14
15
 (test-dependencies
   test)
 (components
   (extension lmdb
     (custom-build "build-lmdb")
     (source-dependencies "lmdb.h" "mdb.impl.c" "midl.h" "midl.impl.c"))))

;; vim: set ai et ts=4 sts=2 sw=2 ft=scheme: ;;

Changes to lmdb.scm.

607
608
609
610
611
612
613
614
                    val)
                  (%database-set! dbi key val set-flags))))
          alist))
      dbi)))

)

;; vim: set ai et ts=8 sts=2 sw=2 ft=scheme: ;;







|
607
608
609
610
611
612
613
614
                    val)
                  (%database-set! dbi key val set-flags))))
          alist))
      dbi)))

)

;; vim: set ai et ts=4 sts=2 sw=2 ft=scheme: ;;

Changes to lmdb.wiki.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206
207
208
209
210
211
212

213
214
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<h1>LMDB API</h1>

This CHICKEN binding for LMDB consists of a single module in a shared
library of the same name. You can load the library and import the module
using

<verbatim>
  (import lmdb)
</verbatim>


<h2>Database Environments</h2>

<verbatim>
  current-database-environment
</verbatim>

A parameter holding the current database environment pointer or
<tt>#f</tt>.

<verbatim>
  (database-environment? OBJECT) => BOOLEAN
</verbatim>

Type predicate for database environments.

<verbatim>
  (open-database-environment
   PATH
   [#:mode MODE]
   [#:max-databases MAXDBS]
   [#:max-readers MAXREADERS]
   [#:max-size MAPSIZE]
   [#:fixed-map]
................................................................................
   [#:read-only]
   [#:write-map]
   [#:no-meta-sync]
   [#:no-sync]
   [#:map-async]
   [#:no-lock]
   [#:no-read-ahead])
  =>

  ENVIRONMENT
</verbatim>

Creates a database environment and configures various settings through
setup methods and the open method.

Unless <tt>#:no-subdirectory</tt> is specified or the given
<tt>PATH</tt> already exists, <tt>PATH</tt> is created as a directory
to contain the database environment.

Sets <tt>current-database-environment</tt> to the newly created
environment.

<verbatim>
  (close-database-environment [ENVIRONMENT]) => VOID
</verbatim>

Closes a database environment and destroys the handle. If no
<tt>ENVIRONMENT</tt> is specified explicitly, closes the current
environment and sets <tt>current-database-environment</tt> to
<tt>#f</tt>.

<verbatim>
  (copy-database-environment PATH [ENVIRONMENT] [#:compact]) => VOID
</verbatim>

Copies a database environment to a new <tt>PATH</tt>, optionally
compacting the data. If no <tt>ENVIRONMENT</tt> is specified
explicitly, the current environment is copied.

<h2>Transactions</h2>

<verbatim>
  (with-transaction THUNK [ENVIRONMENT] [#:read-only]) => (values ...)
</verbatim>

Wraps a call to <tt>THUNK</tt> in a transaction. Returns whatever
<tt>(THUNK)</tt> returns. If no <tt>ENVIRONMENT</tt> is specified
explicitly, the current environment is used.

The transaction can optionally be configured as read-only. Read-only
transactions may be nested.

All database operations below have to be executed within a transaction.

The transaction is committed upon normal return from <tt>(THUNK)</tt>
and aborted if <tt>(THUNK)</tt> throws an exception.

<verbatim>
  (clear-stale-transactions [ENVIRONMENT]) => INTEGER
</verbatim>

Removes stale read-only transactions from the database lockfile (stale
read-write transactions are usually removed automatically). If no
<tt>ENVIRONMENT</tt> is specified explicitly, the current environment is used.

The procedure returns the number of stale lock file entries that were removed.

<h2>Databases</h2>

<verbatim>
  (database? OBJECT) => BOOLEAN
</verbatim>

Type predicate for databases.

<verbatim>
  (open-database
   [NAME]
   [#:reverse-key]
   [#:duplicate-sort]
   [#:integer-key]
   [#:duplicate-fixed]
   [#:integer-duplicate]
   [#:reverse-duplicate]
   [#:create])
  =>

  DATABASE
</verbatim>

Opens a database and configures various flags.

The name of the database can be omitted if the environment was opened
without <tt>#:max-databases</tt> and consists of only a single default
database.

If a named database does not exist, <tt>#:create</tt> must be specified
when it is first opened.

<verbatim>
  (close-database DATABASE [ENVIRONMENT]) => VOID
</verbatim>

Closes a database. If the <tt>ENVIRONMENT</tt> containing the database
is not specified explicitly, the current environment is assumed.

<verbatim>
  (database-ref DATABASE KEY [DEFAULT]) => VALUE
</verbatim>

Extracts a record with the given <tt>KEY</tt> from the database. If no
record is found and <tt>DEFAULT</tt> is given, it is invoked in case it
is a procedure and returned otherwise. An error is signalled if no
record is found and <tt>DEFAULT</tt> is not given.

Database keys can be strings or blobs. Values extracted from the
database are returned as strings.

<verbatim>
  (database-set!
   DATABASE KEY VALUE
   [#:no-duplicate]
   [#:no-overwrite]
   [#:append]
   [#:append/duplicate])
  =>

  VOID

  (set! (database-ref DATABASE KEY) VALUE) => VOID
</verbatim>

Stores a record in the database with several optional flags modifying
the behaviour.

For databases configured with support for multiple values per key, new
values are normally added to the set of existing ones. For databases
with one value per key, existing records are replaced.

Database keys and values can be strings or blobs.

<verbatim>
  (database-exists? DATABASE KEY) => BOOLEAN
</verbatim>

Checks whether a key exists in the database.

Database keys can be strings or blobs.

<verbatim>
  (database-delete! DATABASE KEY [VALUE]) => VOID
</verbatim>

Deletes a record from the database. An error is signalled if no record
is found.

For databases configured with support for multiple values per key, the
<tt>VALUE</tt> to delete can be specified explicitly. For databases
with one value per key, <tt>VALUE</tt> is ignored.

Database keys and values can be strings or blobs.

<verbatim>
  (database-fold
   PROC SEED DATABASE
   [#:from START] [#:to< | #:to<= STOP] [#:limit LIMIT])
  =>

  (PROC KEY VALUE (... (PROC KEY VALUE SEED)))
</verbatim>

Folds over the records in the database. If <tt>START</tt> is given, only
fold over the records with keys greater than or equal to <tt>START</tt>.
If <tt>STOP</tt> is given, only fold over the records with keys less
than (or equal) to <tt>STOP</tt>. If <tt>LIMIT</tt> is given, process at
most <tt>LIMIT</tt> records before stopping early.

<verbatim>
  (database-walk
   PROC DATABASE
   [#:from START] [#:to< | #:to<= STOP] [#:limit LIMIT])
  =>

  VOID
</verbatim>

Like <tt>database-fold</tt>, but discarding the result.

<verbatim>
  (database->alist
   DATABASE
   [#:from START] [#:to< | #:to<= STOP] [#:limit LIMIT] [#:duplicate-list])
  =>

  ALIST
</verbatim>

Convert the records in the database to an association list. If
<tt>START</tt> is given, only list the records with keys greater than or
equal to <tt>START</tt>. If <tt>STOP</tt> is given, only list the
records with keys less than (or equal) to <tt>STOP</tt>. If
<tt>LIMIT</tt> is given, process at most <tt>LIMIT</tt> records before
stopping early.

Optionally, multiple values for the same key may be folded into lists
rather than producing multiple pairs with the same key in the
association list.

<verbatim>
  (alist->database
   ALIST [NAME]
   [#:reverse-key]
   [#:duplicate-sort]
   [#:integer-key]
   [#:duplicate-fixed]
   [#:integer-duplicate]
   [#:reverse-duplicate]
   [#:create]
   [#:no-duplicate]
   [#:no-overwrite]
   [#:append]
   [#:append/duplicate])
  =>

  DATABASE
</verbatim>

Convert an association list into records in a database. The procedure
accepts the combined flag arguments of <tt>open-database</tt> and
<tt>database-set!</tt>. The procedure returns a new handle to the
database indicated by the given <tt>NAME</tt> or to the default
database.

<tt>ALIST</tt> must contain pairs of keys and values. Keys can be
strings or blobs. Values can be strings, blobs or lists of strings and
blobs. If a value is a list, all its elements are inserted into the
database with the same key.

If <tt>ALIST</tt> was generated by <tt>database->alist</tt>, it is safe
to pass <tt>#:append</tt> or <tt>#:append/duplicate</tt> to this
procedure.


|
|
|

|
|
|
>



|

|




|
|
|



|







 







<
>

|








|
|

|
|
|



|
|

|
|
|







|
|
|













|
|
|









|
|
|



|









<
>

|










|
|
|




|
|
|









|






<
>


|
|










|
|
|





|
|
|










|



<
>

|







|



<
>

|

|

|



<
>

|












|













<
>

|


|
|
|
|






|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206
207
208
209
210
211
212

213
214
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<h1>LMDB API</h1>

<h3 id="m:lmdb"><tt><nowiki>
  (import lmdb)
</nowiki></tt></h3>

This [https://www.call-cc.org/|CHICKEN] binding for [https://symas.com/lmdb/|LMDB]
consists of a single module in a shared library of the same name. It
offers a simple, hash-table-like programming interface to key value
databases stored on disk.

<h2>Database Environments</h2>

<h3 id="p:current-database-environment"><tt><nowiki>
  current-database-environment
</nowiki></tt></h3>

A parameter holding the current database environment pointer or
<tt>#f</tt>.

<h3 id="p:database-environment"><tt><nowiki>
  (database-environment? OBJECT)  BOOLEAN
</nowiki></tt></h3>

Type predicate for database environments.

<h3 id="c:open-database-environment"><tt><nowiki>
  (open-database-environment
   PATH
   [#:mode MODE]
   [#:max-databases MAXDBS]
   [#:max-readers MAXREADERS]
   [#:max-size MAPSIZE]
   [#:fixed-map]
................................................................................
   [#:read-only]
   [#:write-map]
   [#:no-meta-sync]
   [#:no-sync]
   [#:map-async]
   [#:no-lock]
   [#:no-read-ahead])


  ENVIRONMENT
</nowiki></tt></h3>

Creates a database environment and configures various settings through
setup methods and the open method.

Unless <tt>#:no-subdirectory</tt> is specified or the given
<tt>PATH</tt> already exists, <tt>PATH</tt> is created as a directory
to contain the database environment.

Sets [#p:current-database-environment|<tt>current-database-environment</tt>]
to the newly created environment.

<h3 id="d:close-database-environment"><tt><nowiki>
  (close-database-environment [ENVIRONMENT])  VOID
</nowiki></tt></h3>

Closes a database environment and destroys the handle. If no
<tt>ENVIRONMENT</tt> is specified explicitly, closes the current
environment and sets [#p:current-database-environment|<tt>current-database-environment</tt>]
to <tt>#f</tt>.

<h3 id="p:copy-database-environment"><tt><nowiki>
  (copy-database-environment PATH [ENVIRONMENT] [#:compact])  VOID
</nowiki></tt></h3>

Copies a database environment to a new <tt>PATH</tt>, optionally
compacting the data. If no <tt>ENVIRONMENT</tt> is specified
explicitly, the current environment is copied.

<h2>Transactions</h2>

<h3 id="p:with-transaction"><tt><nowiki>
  (with-transaction THUNK [ENVIRONMENT] [#:read-only])  (values ...)
</nowiki></tt></h3>

Wraps a call to <tt>THUNK</tt> in a transaction. Returns whatever
<tt>(THUNK)</tt> returns. If no <tt>ENVIRONMENT</tt> is specified
explicitly, the current environment is used.

The transaction can optionally be configured as read-only. Read-only
transactions may be nested.

All database operations below have to be executed within a transaction.

The transaction is committed upon normal return from <tt>(THUNK)</tt>
and aborted if <tt>(THUNK)</tt> throws an exception.

<h3 id="p:clear-stale-transactions"><tt><nowiki>
  (clear-stale-transactions [ENVIRONMENT])  INTEGER
</nowiki></tt></h3>

Removes stale read-only transactions from the database lockfile (stale
read-write transactions are usually removed automatically). If no
<tt>ENVIRONMENT</tt> is specified explicitly, the current environment is used.

The procedure returns the number of stale lock file entries that were removed.

<h2>Databases</h2>

<h3 id="p:database"><tt><nowiki>
  (database? OBJECT)  BOOLEAN
</nowiki></tt></h3>

Type predicate for databases.

<h3 id="c:open-database"><tt><nowiki>
  (open-database
   [NAME]
   [#:reverse-key]
   [#:duplicate-sort]
   [#:integer-key]
   [#:duplicate-fixed]
   [#:integer-duplicate]
   [#:reverse-duplicate]
   [#:create])


  DATABASE
</nowiki></tt></h3>

Opens a database and configures various flags.

The name of the database can be omitted if the environment was opened
without <tt>#:max-databases</tt> and consists of only a single default
database.

If a named database does not exist, <tt>#:create</tt> must be specified
when it is first opened.

<h3 id="d:close-database"><tt><nowiki>
  (close-database DATABASE [ENVIRONMENT])  VOID
</nowiki></tt></h3>

Closes a database. If the <tt>ENVIRONMENT</tt> containing the database
is not specified explicitly, the current environment is assumed.

<h3 id="p:database-ref"><tt><nowiki>
  (database-ref DATABASE KEY [DEFAULT])  VALUE
</nowiki></tt></h3>

Extracts a record with the given <tt>KEY</tt> from the database. If no
record is found and <tt>DEFAULT</tt> is given, it is invoked in case it
is a procedure and returned otherwise. An error is signalled if no
record is found and <tt>DEFAULT</tt> is not given.

Database keys can be strings or blobs. Values extracted from the
database are returned as strings.

<h3 id="p:database-set!"><tt><nowiki>
  (database-set!
   DATABASE KEY VALUE
   [#:no-duplicate]
   [#:no-overwrite]
   [#:append]
   [#:append/duplicate])


  VOID

  (set! (database-ref DATABASE KEY) VALUE)  VOID
</nowiki></tt></h3>

Stores a record in the database with several optional flags modifying
the behaviour.

For databases configured with support for multiple values per key, new
values are normally added to the set of existing ones. For databases
with one value per key, existing records are replaced.

Database keys and values can be strings or blobs.

<h3 id="p:database-exists"><tt><nowiki>
  (database-exists? DATABASE KEY)  BOOLEAN
</nowiki></tt></h3>

Checks whether a key exists in the database.

Database keys can be strings or blobs.

<h3 id="p:database-delete!"><tt><nowiki>
  (database-delete! DATABASE KEY [VALUE])  VOID
</nowiki></tt></h3>

Deletes a record from the database. An error is signalled if no record
is found.

For databases configured with support for multiple values per key, the
<tt>VALUE</tt> to delete can be specified explicitly. For databases
with one value per key, <tt>VALUE</tt> is ignored.

Database keys and values can be strings or blobs.

<h3 id="p:database-fold"><tt><nowiki>
  (database-fold
   PROC SEED DATABASE
   [#:from START] [#:to< | #:to<= STOP] [#:limit LIMIT])


  (PROC KEY VALUE (... (PROC KEY VALUE SEED)))
</nowiki></tt></h3>

Folds over the records in the database. If <tt>START</tt> is given, only
fold over the records with keys greater than or equal to <tt>START</tt>.
If <tt>STOP</tt> is given, only fold over the records with keys less
than (or equal) to <tt>STOP</tt>. If <tt>LIMIT</tt> is given, process at
most <tt>LIMIT</tt> records before stopping early.

<h3 id="p:database-walk"><tt><nowiki>
  (database-walk
   PROC DATABASE
   [#:from START] [#:to< | #:to<= STOP] [#:limit LIMIT])


  VOID
</nowiki></tt></h3>

Like [#p:database-fold|<tt>database-fold</tt>], but discarding the result.

<h3 id="p:database2alist"><tt><nowiki>
  (database->alist
   DATABASE
   [#:from START] [#:to< | #:to<= STOP] [#:limit LIMIT] [#:duplicate-list])


  ALIST
</nowiki></tt></h3>

Convert the records in the database to an association list. If
<tt>START</tt> is given, only list the records with keys greater than or
equal to <tt>START</tt>. If <tt>STOP</tt> is given, only list the
records with keys less than (or equal) to <tt>STOP</tt>. If
<tt>LIMIT</tt> is given, process at most <tt>LIMIT</tt> records before
stopping early.

Optionally, multiple values for the same key may be folded into lists
rather than producing multiple pairs with the same key in the
association list.

<h3 id="c:alist2database"><tt><nowiki>
  (alist->database
   ALIST [NAME]
   [#:reverse-key]
   [#:duplicate-sort]
   [#:integer-key]
   [#:duplicate-fixed]
   [#:integer-duplicate]
   [#:reverse-duplicate]
   [#:create]
   [#:no-duplicate]
   [#:no-overwrite]
   [#:append]
   [#:append/duplicate])


  DATABASE
</nowiki></tt></h3>

Convert an association list into records in a database. The procedure
accepts the combined flag arguments of [#c:open-database|<tt>open-database</tt>]
and [#p:database-set!|<tt>database-set!</tt>]. The procedure returns a
new handle to the database indicated by the given <tt>NAME</tt> or to
the default database.

<tt>ALIST</tt> must contain pairs of keys and values. Keys can be
strings or blobs. Values can be strings, blobs or lists of strings and
blobs. If a value is a list, all its elements are inserted into the
database with the same key.

If <tt>ALIST</tt> was generated by [#p:database2alist|<tt>database->alist</tt>],
it is safe to pass <tt>#:append</tt> or <tt>#:append/duplicate</tt> to
this procedure.

Changes to tests/run.scm.

77
78
79
80
81
82
83


   (test
     '()
     (database->alist quirks))))

(close-database-environment)

(test-exit)









>
>
77
78
79
80
81
82
83
84
85
   (test
     '()
     (database->alist quirks))))

(close-database-environment)

(test-exit)

;; vim: set ai et ts=4 sts=2 sw=2 ft=scheme: ;;