trailsjs / trails

:evergreen_tree: Modern Web Application Framework for Node.js.
http://trailsjs.io
Other
1.66k stars 70 forks source link

Have the possibility to use multiple ORM #194

Open jaumard opened 8 years ago

jaumard commented 8 years ago

Issue Description

For now we can use only one ORM, when you use Waterline it's fine because it can do nosql and sql but if you don't want to use Waterline and need nosql and sql they are currently no solution. Can be useful on some project to use trailpack-mongoose and trailpack-knex for example. Maybe we can plan this for the v2 ?

Environment

tjwebb commented 8 years ago

I think the key to this is allowing stores to define which datastore provider they use. So if both waterline and knex are installed, we might define stores like so:

{
  stores: {
    store1: {
      provider: 'knex',
      adapter: require('pg')
    },
    store2: {
      provider: 'waterline',
      adapter: require('waterline-postgresql')
    }
  }
}
jaumard commented 8 years ago

@tjwebb really like this proposition ! Each trailpack-datastore need to take care of the provider field to ignore stores that are not under they concern. They also need to don't initialize app.orm if it's already create to not override models from other orm. But this can work very nicely ! And I think it's a cool feature to have in Trails :) have some relational DB and also a nosql DB for realtime append (quite often??)

jaumard commented 8 years ago

On problem I see is currently each ORM trailpack embedded a FootprintService :/ one will be override by the other. We need to have only one FootprintService (maybe in trailpack-datastore) witch call the good ORMFootprintService depend of the store.provider of the model. How does it sound @tjwebb ?

tjwebb commented 8 years ago

Yea, this was lazy design on my part. Instead of simply naming it FootprintService, it would be more flexible to create an abstract FootprintService class which other Footprint Service implementations could inherit from. Then a datastore trailpack could look for services which are of type FootprintService, but not named FootprintService.

konstantinzolotarev commented 7 years ago

Also need this to be implemented to be able to finish with adding Trails.js to benchmark tests.

jaumard commented 7 years ago

Can we plan this @tjwebb or at least a good description (list of tasks) of what need to be done in order to implement this ? @konstantinzolotarev one things that can be done is one Trails project with a default ORM and then some other project that just require the first one and override ORM config before start the server. I do something like this on my tests for trailpack-passport

konstantinzolotarev commented 7 years ago

@jaumard I'll just use orm without trailpacks and it will solve most of this issues. But later on we will have to solve this issue.

jaumard commented 7 years ago

@tjwebb up, what the status on this ? I can help with this