https://github.com/ruby/gdbm
Ruby extension for GNU dbm.
https://github.com/ruby/gdbm
gdbm ruby
Last synced: 6 months ago
JSON representation
Ruby extension for GNU dbm.
- Host: GitHub
- URL: https://github.com/ruby/gdbm
- Owner: ruby
- License: gpl-2.0
- Created: 2017-04-14T10:05:03.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2025-07-21T19:12:16.000Z (9 months ago)
- Last Synced: 2025-07-21T21:28:57.418Z (9 months ago)
- Topics: gdbm, ruby
- Language: C
- Homepage:
- Size: 184 KB
- Stars: 16
- Watchers: 30
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# GDBM
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.
## Installing the required libraries.
### On Debian/Ubuntu
```
sudo apt install libgdbm-dev
```
### On Redhat/Fedora
```
sudo dnf install gdbm-devel
```
or if you are using an older version of Redhat or Fedora that uses Yum:
```
sudo yum install gdbm-devel
```
### On macOS
If you are using Homebrew, you can install gdbm with the following command:
```
brew install gdbm
```
or if you are using MacPorts, you can install gdbm with:
```
sudo port install gdbm
```
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'gdbm'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install gdbm
### Install on macOS with gdbm path.
```
gem install gdbm -- --with-gdbm-dir=$(brew --prefix gdbm)
```
## Usage
1. Opening/creating a database, and filling it with some entries:
require 'gdbm'
```ruby
gdbm = GDBM.new("fruitstore.db")
gdbm["ananas"] = "3"
gdbm["banana"] = "8"
gdbm["cranberry"] = "4909"
gdbm.close
```
2. Reading out a database:
```ruby
require 'gdbm'
gdbm = GDBM.new("fruitstore.db")
gdbm.each_pair do |key, value|
print "#{key}: #{value}\n"
end
gdbm.close
```
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/gdbm.
## License
The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).