I'm facing a situation where I have numerous models for thinky, and in each file I am required to create a new object for thinky and connect it multiple times due to the high number of models.
var dbconfig = require('../config/config.js')['rethinkdb'];
var thinky = require('thinky')(dbconfig);
var User = require('./user.js');
var type = thinky.type;
var r = thinky.r;
var Feedback = thinky.createModel("Feedback", {
id: type.string(),
feel: type.number().required(), // 0 = sad, 1 = happy
reason: type.string(),
description: type.string(),
createdAt: type.date().default(r.now()),
createdBy: type.string().required()
});
Feedback.ensureIndex("id");
module.exports = Feedback;
I'm seeking advice on how to avoid repeatedly instantiating the variable and creating new connections every time while still being able to organize all these data models in their own separate files.