Open kulakowka opened 8 years ago
Sure
:+1:
+1
Added a few basic examples on how to use Mongorito, more coming soon: https://github.com/vdemedes/mongorito/tree/master/examples
Readme got also updated with a lot more specific code snippets and quick docs.
looks coooool~ :+1: Have the road map or coming feature for this project?
Everything that's planned is in the Issues, no separate roadmap yet.
those are pretty convoluted examples can you write one simple self contained example of how to use mongorito?
@dcsan What specifically is unclear to you?
attributes example seems to be the one that actually does something useful.. but how to extract that?
const mongorito = require('../');
where is the connection made?
yield mongorito.connect # has to be defined
const run = require('./run');
function run (fn) {
co(fn).catch(function (err) {
console.error(err.stack);
});
}
run(function * () {
trying to get a single file example to work
i'm not familiar with co
so this is probably obvious to you but ...
the above doesn't run as I guess its still waiting on a generator?
'use strict';
const co = require('co');
const mongorito = require('mongorito');
/*
* Run a generator function and print errors if any
*/
function run (fn) {
co(fn).catch(function (err) {
console.error(err.stack);
});
}
function connect() {
run(function * () {
console.log('connecting');
yield mongorito.connect('localhost/mongorito-test');
console.log('connecting DONE');
});
}
function disconnect() {
run(function * () {
yield mongorito.disconnect();
console.log('disconnected');
});
}
const Model = mongorito.Model;
class Tags extends Model {}
var tag = new Tags({
title: 'cool-stuff',
body: 'info about this tag'
});
function* main() {
console.log('main');
yield connect();
yield tag.save();
console.log('saved');
}
run(main() );
TypeError: You may only yield a function, promise, generator, array, or object, but the following object was passed: "undefined"
how to actually start things off?
Your errors have nothing to do with mongorito. I recommend giving a read on generators and co module one more time. And after that, check out examples again, I'm sure you will find them useful. They have more than enough to get started. Also, of course, readme.
P.S. You don't have to use generators at all, all methods return promises, if you find that more suitable.
OK fair enough, the issues are definitely about how to wrap your library, so it can be used. If you are interested in broadening the appeal, it would be great to see a more easy to modify example. I'm reading up on co() and friends, but there aren't any great references I've found to get going quickly.
i can't get this working either
i want to use babel with this lib
@crapthings if you are getting some errors related to mongorito, open a new issue so that we can discuss.
i can get things work.
https://github.com/crapthings/inventor-server
use babel async await
git clone https://github.com/crapthings/inventor-server
npm install
nodemon loader.js
Bumping. Most examples linked above use older Koa and Mongorito versions and are no longer valid.
Hey everyone, I don't have time to work on this project, so feel free to submit a PR for an example you'd like to see. Thanks for understanding!
@vdemedes can you add a simple koa-application example?