{"size": 439, "ext": "js", "max_stars_repo_path": "generators/app/templates/infrastructure/src/middleware/db/contextDbInstance.js", "max_stars_repo_name": "alexandruchirita4192/generator-graphql-rocket", "max_stars_repo_stars_event_min_datetime": "2020-08-28T11:23:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T16:03:43.000Z", "max_issues_repo_path": "generators/app/templates/infrastructure/src/middleware/db/contextDbInstance.js", "max_issues_repo_name": "alexandruchirita4192/generator-graphql-rocket", "max_issues_repo_issues_event_min_datetime": "2020-09-24T07:53:39.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-20T12:06:19.000Z", "max_forks_repo_path": "generators/app/templates/infrastructure/src/middleware/db/contextDbInstance.js", "max_forks_repo_name": "alexandruchirita4192/generator-graphql-rocket", "max_forks_repo_forks_event_min_datetime": "2020-12-10T09:32:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-13T14:11:15.000Z"}
{"max_stars_count": 25, "max_issues_count": 10, "max_forks_count": 3, "avg_line_length": 23.1052631579, "max_line_length": 57, "alphanum_fraction": 0.6423690205}
const { dbInstanceFactory } = require("../../db");

const contextDbInstance = () => async (ctx, next) => {
  <%_ if(withMultiTenancy){ _%>
  const { tenant } = ctx
  if (tenant) {
    const dbInstance = await dbInstanceFactory(tenant.id)
    ctx.dbInstance = dbInstance
  }
  <%_} else { _%>
    const dbInstance = await dbInstanceFactory()
    ctx.dbInstance = dbInstance
  <%_}_%>

  await next();
};


module.exports = contextDbInstance