Skip to content

Commit

Permalink
Merge pull request #46 from fabrix-app/v1.6
Browse files Browse the repository at this point in the history
feat(models): Select Store by model config
  • Loading branch information
scott-wyatt authored Jun 28, 2019
2 parents 4b7ce11 + 14102c4 commit 2c48b29
Show file tree
Hide file tree
Showing 8 changed files with 596 additions and 559 deletions.
2 changes: 1 addition & 1 deletion lib/SequelizeSpool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DatastoreSpool } from '@fabrix/fabrix/dist/common/spools/datastore'

import * as Sequelize from 'sequelize'
import Sequelize from 'sequelize'

import { Validator } from './validator'
import { Transformer } from './transformer'
Expand Down
2 changes: 1 addition & 1 deletion lib/api/services/SequelizeService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FabrixService as Service } from '@fabrix/fabrix/dist/common'
import { defaults, omitBy, isArray, isObject, isString, isNil } from 'lodash'
import * as merge from 'merge-options'
import merge from 'merge-options'

export class SequelizeService extends Service {
/**
Expand Down
13 changes: 9 additions & 4 deletions lib/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as _ from 'lodash'
// import * as Sequelize from 'sequelize'
import { FabrixApp } from '@fabrix/fabrix'
import { FabrixModel } from '@fabrix/fabrix/dist/common'
import { pickBy, isString, startsWith } from 'lodash'
Expand Down Expand Up @@ -179,9 +177,16 @@ export const Transformer = {
defineModel: (app: FabrixApp, sequelize, model: FabrixModel, connections) => {
const modelName = model.constructor.name
const modelConfig = model.config
const store = modelConfig.store || app.config.get('models.defaultStore')
const store = modelConfig.store
|| app.config.get(`models.${modelName}.store`)
|| app.config.get('models.defaultStore')

const connection = connections[store]
const migrate = modelConfig.migrate || app.config.get('models.migrate') || connection.migrate
const migrate = modelConfig.migrate
|| app.config.get(`models.${modelName}.migrate`)
|| app.config.get('models.migrate')
|| connection.migrate

const options = Transformer.getModelOptions(app, sequelize, model)
const schema = Transformer.getModelSchema(app, sequelize, model)

Expand Down
2 changes: 2 additions & 0 deletions lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"declaration": true,
"strict": false,
"noImplicitAny": false,
"esModuleInterop": true,
"sourceMap": true,
"typeRoots": [
"node_modules/@types"
],
Expand Down
2 changes: 1 addition & 1 deletion lib/validator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as joi from 'joi'
import joi from 'joi'
import { Schemas } from './schemas'

export const Validator = {
Expand Down
Loading

0 comments on commit 2c48b29

Please sign in to comment.