1. NaviServer
  2. NaviServer Project
  3. nsdbbdb

Overview

BerkeleyDB database driver for NaviServer 4.x
Release 0.1
vlad@crystalballinc.com

This is NaviServer module that implements database driver for BerkeleyDB
from www.sleepycat.com

/*--------------------------------------------------------------------*/

Compiling and Installing

To compile this driver, you'll need to have BerkeleyDB library installed,
current Makefile assumes that it is installed in /usr/include/ and
library is /usr/lib/libdb.so.
NaviServer can be installed or source distribution may be used.
There is variable CDFLAGS and CDLIBS in the Makefile which points to 
installation/distribution directory.

Configuring

ns_section      "ns/db/drivers"
ns_param        berkeleydb      nsberkeleydb.so

ns_section      "ns/db/pools"
ns_param        berkeleydb      "Berkeley DB"

ns_section      "ns/db/pool/berkeleydb"
ns_param        driver                  berkeleydb
ns_param        datasource              btree:/tmp/bdb.db
ns_param        home                    /tmp
ns_param	delimiter		"\n"
ns_param	dbflags			"dup"
ns_param	envflags		"nolog,notxn"
ns_param	pagesize		0
ns_param	cachesize		0
ns_param	hfactor			0
ns_param	btminkey		0
ns_param	dbsync			true
ns_param	debug			false

where

    datasource      - path to database file, can be prepend with
                      btree: or hash: to specify database type.
                      Example: hash:/tmp/db.db
    home            - specifies home directory for DB environment
    delimiter       - key and data delimiter in PUT command, default is \n
    dbflags         - flags for each database file:
                            dup  - allow duplicates
    envflags        - flags for global DB enviromnent:
                            notxn        - do not support transaction
                            nolog        - do not support logging/recovery
                            nolock       - do not do locking
                            noprivate    - allow other processes to access database
    pagesize        - size of the database page
    cachesize       - size of the memory cache
    hfactor         - approximation of the number of keys allowed to accumulate in 
                      any one bucket, determining when the hash table grows or shrinks.
    btminkey        - min number of keys in a btree page
    dbsync          - if true, every flush will call db->sync method to flush
                      pages to disk
    debug           - displays debugging message sin the log

Query Language

Simple query language is used to talk to BerkeleyDB driver.
The following commands are available:

   PUT key\ndata
   PUT/a key\ndata
   PUT/d key\ndata
   PUT/o key\ndata
   PUT/ad key\ndata
   PUT/ao key\ndata
   PUT/do key\ndata
   PUT/ado key\ndata
   
     Updates/adds new key/data pair to the database. By default 
     delimiter between key and data is set to newline(\n) but can be changed
     unsing delimiter ns_param options.
     
     Form PUT/flags adds additional flags to the put operations, any combination 
     of flags can be specified after /. the flags are:
     
     a - DB_APPEND
     d - DB_NODUPDATA
     o - DB_NOOVERWRITE
     
     Example:
        ns_db $db exec "PUT VA\nVirginia"
        ns_db $db exec "PUT VT\nVermont"
        ns_db $db exec "PUT NY\nNew York"
        ns_db $db exec "PUT/a NY\nNew York City"
        
   DEL key
   
      Deletes key/data pair
      
      Example:
        ns_db $db exec "DEL NY"
        

   GET key
   
      Retrieves data by specified key.
      
      Example:
        set query [ns_db 0or1row $db "GET VA"]
        set result [ns_set value $query 0]


   CURSOR
   CURSOR key
   
      Retrieves all or matching records. If optional key is specified, then 
      cursor will be initially set to nearest matching record greater or 
      equal to the key.
      
      Example:
      
      set result ""
      set query [ns_db select $db "CURSOR V"]
      while { [ns_db getrow $db $query] } {
        set row ""
        for { set i 0 } { $i < [ns_set size $query] } { incr i } {
          lappend row [ns_set value $query $i]
        }
        lappend result $row
      }
      

   BEGIN
   
      Starts a transaction
      
      Example:
        ns_db $db exec "BEGIN"
      

   COMMIT
   
      Commits a transaction
      
      Example:
        ns_db $db exec "COMMIT"

   ABORT
   
      Aborts a transaction

      Example:
        ns_db $db exec "ABORT"

   COMPACT
   
      Cmpacts Btree and Recno access method databases

      Example:
        ns_db $db exec "COMPACT"

   TRUNCATE
   
      Empties the database

      Example:
        ns_db $db exec "TRUNCATE"
	
Authors

     Vlad Seryakov vlad@crystalballinc.com