2

I have a simple application that connects to two datasources. One being mongo, in which I use mongoose for my ORM, mainly because it has some great functionality for my use. The other is mysql which I am using jugglingdb with the mysql adapter. As I am a newby on jugglingdb I have a few questions regarding its organization.

  1. Can you have your schema objects in multiple files? Mongoose allows you to create schema objects in different files and allow you to reference them with mongoose.model("mymodel"), however, the limited documentation for jugglingdb has all its schema defined in one file. I was wondering how you reference your schema objects that you have defined. My effort so far has been to remove the connection info from them the main schema object and put it in another file like so.

    var Schema = require('jugglingdb').Schema;
    
    
    var TestSchema = function () {
        var schema = new Schema('mysql', {
            database: 'MyDB',
            username: 'blah',
            host: 'localhost',
            password: 'blah',
            port: '3306'
        });
    
        return schema;
    };
    
    module.exports = TestSchema;
    

    Then I would add each schema object in their own respective file and require the above code like so:

    var Test = require('../../db/jugglin_conn')
        , schema = new Test();
    
    var Email = schema.define('email', {
         email: {type: String, required: true}
    });
    

So the main question I have is that is this the way to do it, and if so, how do I pool connections? Secondary question I have is how does someone reference the other "models" or "schema objects" in jugglingdb?

britztopher
  • 1,214
  • 2
  • 16
  • 26

0 Answers0