Created
May 25, 2012 14:34
-
-
Save freewind/2788457 to your computer and use it in GitHub Desktop.
streamline -> js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
var testing_data = require('./data'); | |
var models = require('../models'); | |
exports.connect = function(_) { | |
var state = mongoose.connection.readyState; | |
if(state===0 || state===3 ) { | |
mongoose.connect('mongo://localhost/shuzu_test',_); | |
} | |
} | |
exports.close = function(_) { | |
mongoose.connection.close(_); | |
} | |
exports.initdb = function(_) { | |
exports.connect(_); | |
var db = mongoose.connection.db; | |
// Since drop database is slow, so I just drop collections | |
// drop collections | |
console.log(db.collectionNames(_)); | |
db.collections(_).forEach_(_, function(_, col) { | |
if(col.collectionName.indexOf('.')<0) { | |
col.drop(_); | |
} | |
}); | |
console.log('mongodb collections droped'); | |
// insert data | |
var values = []; | |
for(var key in testing_data) values=values.concat(testing_data[key]); | |
console.log(values.length); | |
values.forEach_(_, function(_, obj) { | |
obj.save(_); | |
}); | |
console.log('try to close'); | |
console.log('articles count:' + models.Article.count({},_)); | |
exports.close(_); | |
console.log('mongodb inited'); | |
}; | |
if(module === require.main) { | |
console.log('############################sddssdf'); | |
exports.initdb(function(err){ | |
console.log(err); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** Generated by streamline 0.3.6 (callbacks) - DO NOT EDIT ***/ | |
var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename),__func=__rt.__func,__cb=__rt.__cb,__propagate=__rt.__propagate,__trap=__rt.__trap,__future=__rt.__future,__setEF=__rt.__setEF,__g=__rt.__g; | |
/* 1 */ var mongoose = require("mongoose"); | |
/* 2 */ var testing_data = require("./data"); | |
/* 3 */ var models = require("../models"); | |
/* 5 */ exports.connect = function exports_connect__1(_) { | |
var state; | |
var __frame = { | |
name: "exports_connect__1", | |
line: 5 | |
}; | |
return __func(_, this, arguments, exports_connect__1, 0, __frame, function __$exports_connect__1() { | |
/* 6 */ state = mongoose.connection.readyState; | |
return (function __$exports_connect__1(__then) { | |
/* 7 */ if (((state === 0) || (state === 3))) { | |
/* 8 */ return mongoose.connect("mongo://localhost/shuzu_test", __cb(_, __frame, 3, 8, __then, true)); | |
} | |
else { | |
__then(); | |
} | |
; | |
})(_); | |
}); | |
}; | |
/* 12 */ exports.close = function exports_close__2(_) { | |
var __frame = { | |
name: "exports_close__2", | |
line: 12 | |
}; | |
return __func(_, this, arguments, exports_close__2, 0, __frame, function __$exports_close__2() { | |
/* 13 */ return mongoose.connection.close(__cb(_, __frame, 1, 4, _, true)); | |
}); | |
}; | |
/* 16 */ exports.initdb = function exports_initdb__3(_) { | |
var db, values, key; | |
var __frame = { | |
name: "exports_initdb__3", | |
line: 16 | |
}; | |
return __func(_, this, arguments, exports_initdb__3, 0, __frame, function __$exports_initdb__3() { | |
/* 17 */ return exports.connect(__cb(_, __frame, 1, 4, function __$exports_initdb__3() { | |
/* 18 */ db = mongoose.connection.db; | |
/* 23 */ return db.collectionNames(__cb(_, __frame, 7, 16, function ___(__0, __3) { | |
/* 23 */ console.log(__3); | |
/* 24 */ return db.collections(__cb(_, __frame, 8, 4, function ___(__0, __4) { | |
/* 24 */ return __4.forEach_(__cb(_, __frame, 8, 4, function __$exports_initdb__3() { | |
/* 29 */ console.log("mongodb collections droped"); | |
/* 32 */ values = []; | |
/* 33 */ for (key in testing_data) { | |
/* 33 */ values = values.concat(testing_data[key]); | |
}; | |
/* 35 */ console.log(values.length); | |
/* 36 */ return values.forEach_(__cb(_, __frame, 20, 4, function __$exports_initdb__3() { | |
/* 40 */ console.log("try to close"); | |
/* 41 */ return models.Article.count({ | |
}, __cb(_, __frame, 25, 36, function ___(__0, __5) { | |
/* 41 */ console.log(("articles count:" + __5)); | |
/* 42 */ return exports.close(__cb(_, __frame, 26, 4, function __$exports_initdb__3() { | |
/* 43 */ console.log("mongodb inited"); | |
_(); | |
}, true)); | |
}, true)); | |
/* 36 */ }, true), function __2(_, obj) { | |
var __frame = { | |
name: "__2", | |
line: 36 | |
}; | |
return __func(_, this, arguments, __2, 0, __frame, function __$__2() { | |
/* 37 */ return obj.save(__cb(_, __frame, 1, 8, _, true)); | |
}); | |
}); | |
/* 24 */ }, true), function __1(_, col) { | |
var __frame = { | |
name: "__1", | |
line: 24 | |
}; | |
return __func(_, this, arguments, __1, 0, __frame, function __$__1() { | |
return (function __$__1(__then) { | |
/* 25 */ if ((col.collectionName.indexOf(".") < 0)) { | |
/* 26 */ return col.drop(__cb(_, __frame, 2, 12, __then, true)); | |
} | |
else { | |
__then(); | |
} | |
; | |
})(_); | |
}); | |
}); | |
}, true)); | |
}, true)); | |
}, true)); | |
}); | |
}; | |
/* 46 */ if ((module === require.main)) { | |
/* 47 */ console.log("############################sddssdf"); | |
/* 48 */ exports.initdb(function(err) { | |
/* 49 */ console.log(err); | |
}); | |
} | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment