Skip to content

AsyncLocalStorage for query options #648

@IlyaSemenov

Description

@IlyaSemenov

As per #303, we have an option to override log settings inside a certain (sub-)transaction. I believe this is incorrect coupling; I am now in need to disable logging for a certain execution path without having to use transactions.

I propose to decouple log option from transaction AsyncLocalStorage to an individual local storage with its own life cycle, and something like

await db.withOptions({ log: true}, async () => {
 // all queries will be logged here
})

This has a potential to store more options. For example, as I elaborated in #642, it would be great to have a wrapper that binds db.options.schema into unbound raw-sql refs. Then, we could do:

await db.withOptions({ schema: currentTenant.schema }, async () => {
 await doWork()
})

async function doWork() {
 // this will automatically fetch from `tenant.table`
 await db.query`SELECT * FROM ${db.ref('table')}`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions