You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using AdonisJs v6 and Lucid orm, and have this working controller code but the middleware does not work:
exportdefaultclassSubmissionController{constructor(){this.getSchema=this.getSchema.bind(this)}getSchema(request: HttpContext['request']){constcompanyId=request.header('company-id')return`company_${companyId}`}asyncindex({ request, response }: HttpContext){constschema=this.getSchema(request)constsubmissions=awaitSubmission.query().withSchema(schema)returnresponse.ok(submissions)}asyncstore({ request, response }: HttpContext){const{ data }=request.only(['data'])constschema=this.getSchema(request)constsubmission=awaitdb.insertQuery().withSchema(schema).table('submissions').insert({ data }).returning('*')returnresponse.created(submission)}}
Here's the middleware, I attempted which does not work:
exportdefaultclassSetSchemaMiddleware{asynchandle(ctx: HttpContext,next: NextFn){constcompanyId=ctx.request.header('company-id')constschema=`company_${companyId}`if(schema){//the following does not work// db.query().withSchema(schema)// db.insertQuery().withSchema(schema)}awaitnext()}}
As the title suggests, I want the controller clean from any additional schema related task using a middleware.
Is there a way, where I can bind or assign or something to db call/query with .withSchema() and not have to append that in controller?
I basically want to change
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using AdonisJs v6 and Lucid orm, and have this working controller code but the middleware does not work:
Here's the middleware, I attempted which does not work:
As the title suggests, I want the controller clean from any additional schema related task using a middleware.
Is there a way, where I can bind or assign or something to db call/query with
.withSchema()
and not have to append that in controller?I basically want to change
into
Any help would be welcome.
Beta Was this translation helpful? Give feedback.
All reactions