-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-cursor.js
137 lines (134 loc) · 3.34 KB
/
test-cursor.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
var lsql = require("./index.js");
//var models = require("./Models/linkModel.js");
var async = require("async");
var util = require("util");
var extendedM = new lsql.Model("Extended", {
_id:{type:lsql.Types.Number, autoIncrement:true, primaryKey:true},
foo:lsql.Types.String,
bar:lsql.Types.Number
});
var anotherM = new lsql.Model("Another", {
_id:{type:lsql.Types.Number, autoIncrement:true, primaryKey:true},
rand:lsql.Types.String
});
var basicM = new lsql.Model("Basic", {
_id:{type:lsql.Types.Number, autoIncrement:true, primaryKey:true},
extended:lsql.hasOne(extendedM)
});
//var m = new lsql.Model("testing", {"id":lsql.Types.String, "encounters":lsql.hasMany(new lsql.Model("testing2"))});
//var m = models.Links;
var fieldId = 0;
lsql.connectToDB("./testing.sqlite", function(err) {
async.series([
function(cb) {
extendedM.create(function(err) {
basicM.create(cb);
})
},
function(cb) {
extendedM.clear(function(err) {
basicM.clear(cb);
})
},
function(cb) {
var entry = basicM.new();
entry.extended.foo = "testing";
entry.extended.bar = 5;
entry.save(function(err, id){
fieldId = id;
console.log("Done: " + util.inspect(arguments));
cb();
});
},
function(cb) {
basicM.find({_id:fieldId}).one(function(entry) {
console.log("Basic query: " + util.inspect(entry));
cb();
});
},
function(cb) {
basicM.find({"extended.bar":5}).one(function(entry) {
console.log("Extended sub query: " + util.inspect(entry));
cb();
});
}
]);
/*
async.series([
function(cb) {
console.log("Creating all models");
m.create(function(err) {
models.Encounters.create(function(err) {
models.Embed.create(function (err) {
console.dir(err);
cb();
});
});
});
},
function(cb) {
console.log("Clearing all models");
m.clear(function(err) {
models.Encounters.clear(function(err) {
models.Embed.clear(cb);
});
});
},
function(cb) {
var entry = m.new();
entry.link = "http://www.sparecog.com";
entry.save(function() {
cb();
});
},
function(cb) {
m.count(function(err, count) {
console.log("Count is " + count);
cb();
});
},
function(cb) {
m.find({link:"http://www.sparecog.com"}).one(function(row) {
row.update({text:"This is a test ~!@#$%^&*()_+-=[]\{}|;':\",./<>?∑´®†¥˙∆˜∫√ƒ©†¥¨"});
row.save(cb);
});
},
function(cb) {
var embed = models.Embed.new();
embed.version = "1.0";
embed.type = "html";
embed.save(function (err, id) {
m.find({link:"http://www.sparecog.com"}).one(function(row) {
row.embedID = id;
row.save(cb);
});
});
}
]);
*/
/*
m.find({id:"a1b2c3"}).sort({"id":1}).limit(10).each(function(row) {
console.log("Row id: " + row.id);
var newEncounter = row.encounters.new();
newEncounter.insert(function(err) {
console.log(err);
});
row.encounters.find().sort({"at":-1}).limit(1).one(function(err, item) {
console.log("encounters item is " + item);
});
}, function() {
if (err) {
console.log("Error on find: " + err);
return;
}
console.log("All rows done");
/*
var entry = m.new()
entry.id = "testa";
entry.insert(function(err) {
if (err) console.log(err.message);
console.log("Done with insert");
});
});
*/
});