forked from gabipetrovay/node-orientdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocument_save.js
65 lines (47 loc) · 1.63 KB
/
document_save.js
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
var assert = require("assert");
var orient = require("../lib/orientdb"),
Db = orient.Db,
Server = orient.Server;
var serverConfig = require("../config/test/serverConfig");
var dbConfig = require("../config/test/dbConfig");
var server = new Server(serverConfig);
var db = new Db("temp", server, dbConfig);
//var binary_data = new Buffer(1);
//binary_data.writeUInt8(42, 0);
var name1 = "IIIIIIIIIIIIIII",
name2 = "OOOOOOOOOOOOOOO",
clazz = "FantasyPerson";
var document = {
"@class": clazz,
name: name1,
birthday: new Date(),
fingers: 20,
//fav_binary_number: binary_data,
like_it: true,
linked_to: "#4:0",
last_time_in: { name: "Turin", when: new Date() },
known_os_list: [ "linux" ],
zero_is: null
};
db.open(function(err, result) {
assert(!err, "Error while opening the database: " + err);
// save the first version of the document
db.save(document, function(err, document) {
console.log("Saved document: " + JSON.stringify(document));
var doc_id = document["@rid"];
assert.equal(clazz, document["@class"]);
assert(doc_id);
assert.equal(0, document["@version"]);
assert.equal(name1, document.name);
// change the name
document.name = name2;
// save the sexond version of the document
db.save(document, function(err, document) {
console.log("Updated document: " + JSON.stringify(document));
assert.equal(doc_id, document["@rid"]);
assert.equal(1, document["@version"]);
assert.equal(name2, document.name);
db.close();
});
});
});