Documentation
¶
Overview ¶
Package ndbm implements the ndbm(3) interface of Berkeley DB 1.85 on top of a hash database, file compatible with dbm_open(3).
Example ¶
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/dim13/db"
"github.com/dim13/db/ndbm"
)
func main() {
name := filepath.Join(os.TempDir(), "example") // creates example.db
defer os.Remove(name + ndbm.Suffix)
d, err := ndbm.Open(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
log.Fatal(err)
}
defer d.Close()
if err := d.Store([]byte("key"), []byte("content"), db.DBMReplace); err != nil {
log.Fatal(err)
}
v, err := d.Fetch([]byte("key"))
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", v)
}
Output: content
Index ¶
Examples ¶
Constants ¶
View Source
const Suffix = ".db"
Suffix is appended to the name given to Open, as in C.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBM ¶
type DBM struct {
// contains filtered or unexported fields
}
DBM is an open ndbm database, safe for concurrent use. FirstKey and NextKey share a single cursor.
func Open ¶
Open opens or creates name with Suffix appended. The flag and perm are those of os.OpenFile; a flag without os.O_RDWR opens read-only. The caller must Close the database to write changes.
func (*DBM) FirstKey ¶
FirstKey returns the first key in hash order, or db.ErrNotFound if the database is empty.
Click to show internal directories.
Click to hide internal directories.