- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378 (0)
- 1_9_2_180 (0)
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
Summary
Ruby extension for GNU dbm (gdbm) – a simple database engine for storing key-value pairs on disk.
Description
GNU dbm is a library for simple databases. A database is a file that stores key-value pairs. Gdbm allows the user to store, retrieve, and delete data by key. It furthermore allows a non-sorted traversal of all key-value pairs. A gdbm database thus provides the same functionality as a hash. As with objects of the Hash class, elements can be accessed with []. Furthermore, GDBM mixes in the Enumerable module, thus providing convenient methods such as #find, #collect, #map, etc.
A process is allowed to open several different databases at the same time. A process can open a database as a “reader” or a “writer”. Whereas a reader has only read-access to the database, a writer has read- and write-access. A database can be accessed either by any number of readers or by exactly one writer at the same time.
Examples
-
Opening/creating a database, and filling it with some entries:
require 'gdbm' gdbm = GDBM.new("fruitstore.db") gdbm["ananas"] = "3" gdbm["banana"] = "8" gdbm["cranberry"] = "4909" gdbm.close
-
Reading out a database:
require 'gdbm' gdbm = GDBM.new("fruitstore.db") gdbm.each_pair do |key, value| print "#{key}: #{value}\n" end gdbm.close
produces
banana: 8 ananas: 3 cranberry: 4909
Links
Constants
VERSION = rb_str_new2(gdbm_version)
NOLOCK = INT2FIX(GDBM_NOLOCK)
SYNC = INT2FIX(GDBM_SYNC)
FAST = INT2FIX(GDBM_FAST)
NEWDB = flag for #new and #open
WRCREAT = flag for #new and #open
WRITER = flag for #new and #open
READER = flag for #new and #open