This repository has been archived by the owner on Apr 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
README
93 lines (71 loc) · 2.15 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
cpdb - crazy pili's database
1) Introduction
2) Features
3) Requirements
4) Example Code
5) Maintenance
6) Tests
7) Contact
---------------------------------------------------------------------------
Introduction
cpdb is a NoSQL database for node.js.
---------------------------------------------------------------------------
Features
* Stores key / values pairs persistent in the file system
* Supports transactions
* Generate unique keys
---------------------------------------------------------------------------
Requirements
* DB keys must be strings
* DB values must be serializable using JSON.stringify and JSON.parse
---------------------------------------------------------------------------
Example Code
Here's some example code which stores values in a database:
var db = require('cpdb').DB('path/to/my/db/directory');
var trans = db.newTransaction();
trans.set('key', { value: 'hello world!' });
if(somethingWentReallyBad){
trans.rollback();
}
else{
trans.commit(function(){
// success
console.log('Data stored');
},
function(e){
// error
console.log('Error: ' + e);
});
}
And some more code which retrieves values from the database:
var db = require('cpdb').DB('path/to/my/db/directory');
var readOnly = true;
var trans = db.newTransaction(readOnly);
trans.get('key', function(data){
// success
if(data === undefined){
console.log('Nothing stored in DB');
}
else{
console.log('Got ' + data);
}
},
function(e){
// error
console.log('Error: ' + e);
});
---------------------------------------------------------------------------
Maintenance
The database uses some temporary files and folders for implementing
transactions. Sometimes these transaction data is not delete correctly. It is
safe to manually clear the transaction data when all database instances are
shut down.
To clear the transaction data remove the transactions directory below your
database directory.
---------------------------------------------------------------------------
Tests
Execute the tests using make:
$ make test
---------------------------------------------------------------------------
Contact
* Markus Peröbner <markus.peroebner@gmail.com>