definition Couchdb

26 views
Skip to first unread message

claudio

unread,
Apr 14, 2014, 9:24:52 AM4/14/14
to tot...@googlegroups.com
Hi,
i use couchdb in my app with coucher... 

this is the definition/database.js
var couchdb = require('coucher');

framework.database = function(name) {
var dbURL = framework.config['dbUrl'];
return couchdb.init(dbURL + name + '/');
};

now i need to use the db in a model/users.js

var db = framework.database('users');

function insertNewUser(data, success){

db.insert(data, function(error, data) {
console.log(data);
});

}

exports.insertNewUser = insertNewUser;

but when i call a module from controller for insert the user, it push the user in no-sql db.... it make a folder databases with users file.

how can i solve this?

Thanks Claudio

Peter Širka

unread,
Apr 15, 2014, 6:23:28 AM4/15/14
to tot...@googlegroups.com
Hi Claudio,
this must work (I tested it now). Check version of framework.
If the problem will persist, please send me a small example.

Thanks.

claudio

unread,
Apr 15, 2014, 6:26:38 AM4/15/14
to tot...@googlegroups.com
The framework version is 1310

I'll send you an email with the sample project... Thanks

Peter Širka

unread,
Apr 15, 2014, 7:04:33 AM4/15/14
to
The problem:

- use model instead of module because the model is initialized when is needed
- or use:

var db = null;

framework
.on('load', function() {
    db
= framework.database('easyplant_users');
});

Why? Because your db refers to old function.

claudio

unread,
Apr 15, 2014, 8:00:38 AM4/15/14
to tot...@googlegroups.com
Thanks with on load now it work.... 

You think that use a model instead module is more appropriate?


Peter Širka

unread,
Apr 15, 2014, 8:04:26 AM4/15/14
to tot...@googlegroups.com
In your case yes. User is the model. Module adds new functionality and model creates model/schema operations.
Thanks.

This is my tip, not obligation.
Reply all
Reply to author
Forward
0 new messages