Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 338 lines (301 sloc) 8.115 kB
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
1 nosqlite: require "../nosqlite"
2 sqlite: require "../sqlite"
3 sys: require "sys"
4 fs: require "fs"
5 assert: require "assert"
b0026b9 @mrjjwright Added cakefile and tests
authored
6
7 remove_file: (file) ->
8 try
9 fs.unlinkSync(file)
10 catch err
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
11 sys.puts err
b0026b9 @mrjjwright Added cakefile and tests
authored
12
13
14 test_find: ->
15 db_file: "./test/test_find.db"
16 remove_file(db_file)
17
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
18 db: nosqlite.connect db_file, ->
b0026b9 @mrjjwright Added cakefile and tests
authored
19 log: {
20 text: "hello",
21 occurred_at: new Date().getTime(),
22 created_at: new Date().getTime(),
23 updated_at: new Date().getTime(),
24 source: "string1",
25 log_type: "string1",
26 geo_lat: "string1",
27 geo_long: "string1",
28 metric: 5,
29 external_id: 10,
30 level: 5,
31 readable_metric: "5 miles",
32 facts: ["hello", "hello", "hello1"],
33 original: {id: 1, text: "some crazy object"}
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
34 }
35
36 db.save("log", log, (res) ->
37 db.find("log", {text: "hello"}, (err, result) ->
38 db.close(->
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
39 assert.equal(result.text, "hello", "should find single object")
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
40 )
41 )
42 )
43
44 test_save_cd: ->
45 db_file: "./test/test_save_cd.db"
46 remove_file(db_file)
47 options: {}
48 options.core_data_mode: true
49 db: nosqlite.connect db_file, ->
b0026b9 @mrjjwright Added cakefile and tests
authored
50 log: {
51 text: "hello",
52 occurred_at: new Date().getTime(),
53 created_at: new Date().getTime(),
54 updated_at: new Date().getTime(),
55 source: "string1",
56 log_type: "string1",
57 geo_lat: "string1",
58 geo_long: "string1",
59 metric: 5,
60 external_id: 10,
61 level: 5,
62 readable_metric: "5 miles",
63 facts: ["hello", "hello", "hello1"],
64 original: {id: 1, text: "some crazy object"}
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
65 }
66
67 db.save("log", log, (err, res) ->
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
68 assert.equal(res, "success", "should save single obj")
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
69 )
70
71
72 test_save: ->
73 db_file: "./test/test_save.db"
74 remove_file(db_file)
75
76 db: nosqlite.connect db_file, ->
b0026b9 @mrjjwright Added cakefile and tests
authored
77 log: {
78 text: "hello",
79 occurred_at: new Date().getTime(),
80 created_at: new Date().getTime(),
81 updated_at: new Date().getTime(),
82 source: "string1",
83 log_type: "string1",
84 geo_lat: "string1",
85 geo_long: "string1",
86 metric: 5,
87 external_id: 10,
88 level: 5,
89 readable_metric: "5 miles",
90 facts: ["hello", "hello", "hello1"],
91 original: {id: 1, text: "some crazy object"}
92 }
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
93
94 db.save("log", log, false, (err, res) ->
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
95 assert.equal(res, "success", "should save single obj")
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
96 db.close()
97 )
98
99 test_save_multiple: ->
100 db_file: "./test/test_save_multiple.db"
101 remove_file(db_file)
102
103 db: nosqlite.connect db_file, ->
104 logs: [
105 log: {
106 text: "hello",
107 occurred_at: new Date().getTime(),
108 created_at: new Date().getTime(),
109 updated_at: new Date().getTime(),
110 source: "string2",
111 log_type: "string1",
112 geo_lat: "string1",
113 geo_long: "string1",
114 metric: 5,
115 external_id: 10,
116 level: 5,
117 readable_metric: "5 miles",
118 facts: ["hello", "hello", "hello1"],
119 original: {id: 1, text: "some crazy object"}
120 },
121 log: {
122 text: "hello",
123 occurred_at: new Date().getTime(),
124 created_at: new Date().getTime(),
125 updated_at: new Date().getTime(),
126 source: "string1",
127 log_type: "string1",
128 geo_lat: "string1",
129 geo_long: "string1",
130 metric: 5,
131 external_id: 10,
132 level: 5,
133 readable_metric: "5 miles",
134 facts: ["hello", "hello", "hello1"],
135 original: {id: 1, text: "some crazy object"}
136 },
137 log: {
138 text: "hello",
139 occurred_at: new Date().getTime(),
140 created_at: new Date().getTime(),
141 updated_at: new Date().getTime(),
142 source: "string1",
143 log_type: "string1",
144 geo_lat: "string1",
145 geo_long: "string1",
146 metric: 5,
147 external_id: 10,
148 level: 5,
149 readable_metric: "5 miles",
150 facts: ["hello", "hello", "hello1"],
151 original: {id: 1, text: "some crazy object"}
152 }
153 ]
b0026b9 @mrjjwright Added cakefile and tests
authored
154
155
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
156 db.save("log", logs, false, (err, res) ->
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
157 assert.equal(res, "success", "should save multiple obj")
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
158 db.close()
159 )
b0026b9 @mrjjwright Added cakefile and tests
authored
160
161
162 test_save_bulk: ->
163 db_file: "./test/test_save_bulk.db"
109fa66 @mrjjwright each record will now be saved with a uuid, added basic web listening …
authored
164 remove_file(db_file)
165 options: {}
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
166 options.no_guid: false
b0026b9 @mrjjwright Added cakefile and tests
authored
167
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
168 db: nosqlite.connect db_file, options, ->
b0026b9 @mrjjwright Added cakefile and tests
authored
169 log: {
170 text: "hello",
171 occurred_at: new Date().getTime(),
172 created_at: new Date().getTime(),
173 updated_at: new Date().getTime(),
174 source: "string1",
175 log_type: "string1",
176 geo_lat: "string1",
177 geo_long: "string1",
178 metric: 5,
179 external_id: 10,
180 level: 5,
181 readable_metric: "5 miles",
182 facts: ["hello", "hello", "hello1"],
183 original: {id: 1, text: "some crazy object"}
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
184 }
185
186 logs: []
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
187 for i in [1..200000]
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
188 logs.push(_.clone(log))
189
190 db.save("log", logs, false, (err, res) ->
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
191 assert.equal(res, "success", "should save 250000 log messages quickly")
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
192 db.close()
193 )
194
195
196 test_find_or_save: ->
197 db_file: "./test/test_find_or_save.db"
198 remove_file(db_file)
199
200 db: nosqlite.connect db_file, ->
201 logs: [
202 log: {
203 text: "hello",
204 occurred_at: new Date().getTime(),
205 created_at: new Date().getTime(),
206 updated_at: new Date().getTime(),
207 source: "string1",
208 log_type: "string1",
209 geo_lat: "string1",
210 geo_long: "string1",
211 metric: 5,
212 external_id: 10,
213 level: 5,
214 readable_metric: "5 miles",
215 facts: ["hello", "hello", "hello1"],
216 original: {id: 1, text: "some crazy object"}
217 },
218 log: {
219 text: "hello",
220 occurred_at: new Date().getTime(),
221 created_at: new Date().getTime(),
222 updated_at: new Date().getTime(),
223 source: "string1",
224 log_type: "string1",
225 geo_lat: "string1",
226 geo_long: "string1",
227 metric: 5,
228 external_id: 10,
229 level: 5,
230 readable_metric: "5 miles",
231 facts: ["hello", "hello", "hello1"],
232 original: {id: 1, text: "some crazy object"}
233 },
234 log: {
235 text: "hello2",
236 occurred_at: new Date().getTime(),
237 created_at: new Date().getTime(),
238 updated_at: new Date().getTime(),
239 source: "string1",
240 log_type: "string1",
241 geo_lat: "string1",
242 geo_long: "string1",
243 metric: 5,
244 external_id: 10,
245 level: 5,
246 readable_metric: "5 miles",
247 facts: ["hello", "hello", "hello1"],
248 original: {id: 1, text: "some crazy object"}
249 }
250 ]
251
252 db.find_or_save("log", {text: "hello"}, logs, (err, res) ->
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
253 assert.equal(res, 2, "should save not find these obj")
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
254 db.close()
255 )
256
257
258 test_save_web: ->
259
348345e @mrjjwright updraded web api to node 0.1.90 apis
authored
260 db_file: "./test/test_save_bulk.db"
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
261 rest: require "restler" if not rest?
262
263 #start the listener
264 db: nosqlite.connect db_file, ->
265 server: db.listen(5000)
266
b0026b9 @mrjjwright Added cakefile and tests
authored
267 log: {
268 text: "hello",
269 occurred_at: new Date().getTime(),
270 created_at: new Date().getTime(),
271 updated_at: new Date().getTime(),
272 source: "string1",
273 log_type: "string1",
274 geo_lat: "string1",
275 geo_long: "string1",
276 metric: 5,
277 external_id: 10,
278 level: 5,
279 readable_metric: "5 miles",
280 facts: ["hello", "hello", "hello1"],
281 original: {id: 1, text: "some crazy object"}
282 }
109fa66 @mrjjwright each record will now be saved with a uuid, added basic web listening …
authored
283
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
284 url: "http://localhost:5000?method=save&table=log"
285 rest.post(url, {data: JSON.stringify(log)}).addListener("complete", (data) ->
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
286 assert.equal(data, "success,", "should save record over http")
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
287 predicate: {text: "hello"}
288 find_url: "http://localhost:5000?method=find&table=log"
289 data = [predicate, log]
290 rest.post(find_url, {data: JSON.stringify(data)}).addListener("complete", (data) ->
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
291 assert.equal(data, JSON.stringify([log]), "should find record over http")
ecac378 @mrjjwright now using orlandos async node-sqlite and flow.js
authored
292 server.close()
293 )
109fa66 @mrjjwright each record will now be saved with a uuid, added basic web listening …
authored
294 )
a18f87f @mrjjwright fixed some migration code
authored
295
296
297 test_migration: ->
298
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
299 db_file: "./test/test_save_bulk.db"
300 options: {}
301 options.no_guid: true
302 #remove_file(db_file)
a18f87f @mrjjwright fixed some migration code
authored
303
304 #create schema 1
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
305 db: nosqlite.connect db_file, options, ->
a18f87f @mrjjwright fixed some migration code
authored
306 log: {
307 text: "hello",
308 occurred_at: new Date(),
309 created_at: new Date(),
310 updated_at: new Date(),
311 source: "string1",
312 log_type: "string1",
313 geo_lat: "string1",
314 geo_long: "string1",
315 metric: 5,
316 external_id: 10,
317 level: 5,
318 readable_metric: "5 miles",
319 facts: ["hello", "hello", "hello1"],
320 original: {id: 1, text: "some crazy object"}
321 }
322
323 convert_callback: (old_obj) ->
324 old_obj.occurred_at: "Date.parse(old_obj.ocurred_at).getTime()"
325 return old_obj
109fa66 @mrjjwright each record will now be saved with a uuid, added basic web listening …
authored
326
a18f87f @mrjjwright fixed some migration code
authored
327 db.save "log", log, false, (err, res) ->
328 db.migrate_table "log", convert_callback, (err, res)->
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
329 if err? then sys.p err
330 assert.equal(res, "success", "should migrate table from one schema to another")
109fa66 @mrjjwright each record will now be saved with a uuid, added basic web listening …
authored
331
348345e @mrjjwright updraded web api to node 0.1.90 apis
authored
332 #test_find()
333 #test_find_or_save()
334 #test_save()
335 #test_save_multiple()
9db7d0b @mrjjwright added migration utility. Big speed improvements
authored
336 #test_migration()
337 #test_save_bulk()
348345e @mrjjwright updraded web api to node 0.1.90 apis
authored
338 test_save_web()
Something went wrong with that request. Please try again.