Copyright (C) 2000 Shiro Kawai (shiro@acm.org)
DBM-like libraries provides an easy way to store values to a file, indexed by keys. You can think it as a persistent associative memory. This package provides a generic interface to the various dbm-like libraries. Current version hass bridges to gdbm, ndbm and legacy dbm libraries.
You need STk version 4.0.1 or later. STk is available at http://kaolin.unice.fr/stk/. Also a generic serializer package for STk (after 0.3) is required. It is available at http://pracitcal-scheme.net/.
You should have at least one of dbm, ndbm or gdbm library. Gdbm is available at http://www.gnu.org/software/gdbm/gdbm.html.
The most recent version of the document and the package is available at the following URLs. (The package tarball includes the html document).
After ungzip and untar the package, you'll find a directory dbm
.
Just type
./configure
to create a Makefile. Then
make
compiles necessary files. If you like to confirm everything is OK, type
make test
to do some test. You can install the package to the site-scheme location by
make install
The <dbm>
abstract class defines a common interface
to use various DBM-type database packages.
Just to operate on the already created and opened database, require
"dbm"
module.
(require "dbm")
To create or open a database, you need to load at lease one of the following modules. Each module defines its own low-level accessing functions as well as the common interface.
By default, only strings are allowed to keys and values.
You can use other Scheme types for keys and values, however,
by specifying a serializer class upon the creation of the
<dbm>
instance. See section 2.5 Object serialization
for details.
By instantiating a subclass of the <dbm>
class, you can
either open an existing database or create a new database.
<dbm>
.
Depending on the actual implementation, path may be used literally as a database filename (gdbm) or some suffixes are added (odbm, ndbm).
The keyword argument rw-mode takes one of the following values:
:read
:write
:create
The keyword argument file-mode takes a number representing
unix file mode to be used when make
needs to create a new
database. The default is #o664. This value may be masked by
the user's umask setting.
DBM interface only takes strings for keys and values by default.
If you need to store other types of objects to the database,
you need to tell the DBM instance how to convert those objects
by serializer keyword argument.
It may take a class object which is a subclass of <serializer>
,
or a value #t
. If it is a subclass of <serializer>
,
a serializer instance of the class is used to convert Scheme objects.
If it is #t
, the standard external representation is used.
See section 2.5 Object serialization for details how this mechanism works.
Once a database object is created, you can use the following methods to access individual key/value pairs. Note that, unless you specify serializer argument when you create the dbm object, keys and values must be strings. See section 2.5 Object serialization for details.
<dbm>
) key value
<dbm>
) key &optional default
<dbm>
) key
<dbm>
) key
To walk over the entire database, following methos are provided.
<dbm>
) procedure
<dbm>
) procedure
dbm-map
.
Database file is closed when it is garbage collected. However, to ensure the modification is properly synchornized, you may want to close the database explicitly
<dbm>
)
<dbm>
)
The low-level interface to the dbm libraries only deals with strings. If you want to store general Scheme objects, you need to specify how to convert back and forth between objects and strings. Different applications need different requirements, so it's not good to implement one specific way in this library.
With :serializer
parameter in the constructor of dbm class,
you can specify your serialization scheme.
#f
string=?
.
#t
write*
to get a string representation of
the object, and read
to get the original object back. This means:
dbm-put!
, but you'll have a trouble
when you try to retrieve the data later.
equal?
<serializer>
<serializer>
defines a common interface
for object serialization. You can pass a serializer implemenation of
your choice.
See http://practical-scheme.net/vault/serializer.html
about the details of serializer.
Module GDBM provides a bridge to the GDBM library. To use GDBM interface, require it as follows:
(require "gdbm")
The GDBM module defines a class <gdbm>
.
These functions are direct interface to the gdbm library. See gdbm manpage for
|GDBM_READERT|
|GDBM_WRITER|
|GDBM_WRCREAT|
|GDBM_NEWDB|
|GDBM_FAST|
|GDBM_SYNC|
|GDBM_NOLOCK|
|GDBM_INSERT|
|GDBM_REPLACE|
|GDBM_CACHESIZE|
|GDBM_FASTMODE|
|GDBM_SYNCMODE|
|GDBM_CENTFREE|
|GDBM_COALESCEBLKS|
(require "ndbm")
(require "odbm")
Jump to: * - d - g - m - n - o - |
|GDBM_CACHESIZE|
|GDBM_CENTFREE|
|GDBM_COALESCEBLKS|
|GDBM_FASTMODE|
|GDBM_FAST|
|GDBM_INSERT|
|GDBM_NEWDB|
|GDBM_NOLOCK|
|GDBM_READERT|
|GDBM_REPLACE|
|GDBM_SYNCMODE|
|GDBM_SYNC|
|GDBM_WRCREAT|
|GDBM_WRITER|
This document was generated on 11 February 2000 using texi2html 1.56k.