mcavage/node-bdb — Issue #2: run ndoe-bdb in express
Author: dreampuf
Created: 2011-11-16 01:45:47+00:00
State: open

I write a view, Get the data from a request.body and put it in a bdb inside.
but when i call bdb_db.put , it just print "Segmentation fault", I can run the node-bdb testcase.

//coffeescript
env_home = "./db"
fs.mkdirSync env_home, 0750 if not path.existsSync(env_home)
bdb_env = new bdb.DbEnv()
stat = bdb_env.openSync home: env_home
assert.equal 0, stat.code, stat.message
bdb_db = new bdb.Db bdb_env
stat = bdb_db.openSync env: bdb_env, file:"db"
assert.equal 0, stat.code, stat.message

class Model
hasPro = Object::hasOwnProperty
constructor:(@db_name, methods)->
@db_name_bf = new Buffer "table:#{ @db_name }"
@db = bdb_db.getSync key:@db_name_bf
if @db.code == 0
@db = JSON.parse @db.value.toString()
console.log @db
else
@db = []
for i, k of methods
@constructor::[i] = k

sync:(cb)->
datas = new Buffer JSON.stringify @db
if cb
console.log {key: @db_name_bf, val: datas}
bdb_db.put {key: @db_name_bf, val: datas}, (res)->
console.log res if res.code != 0
console.log "yy"
cb res
else
bdb_db.putSync {key: @db_name_bf, val: datas}

put:(obj, cb)->
@db.push obj
@sync cb