AdonisJS
Wire Lucid tenancy into the AdonisJS request lifecycle - all three isolation strategies.
tenancyjs-integration-adonis connects tenancy to the AdonisJS 7 request lifecycle. AdonisJS uses its
own ORM, so this pairs with the Lucid adapter - and because Lucid supports
all three isolation strategies, AdonisJS gets the full range out of the box.
ORM: Lucid (AdonisJS's ORM). Row-level, schema-per-tenant, and database-per-tenant are all supported.
tenancy init scaffolds AdonisJS + Lucid end to end, so the fastest path is
npx tenancy init. This page covers the manual wiring.
Install
npm install tenancyjs-core tenancyjs-integration-adonis tenancyjs-adapter-lucidConfigure
Define your tenancy config with defineAdonisTenancyConfig, providing a resolver that turns the request
context into a tenant:
import { defineAdonisTenancyConfig } from "tenancyjs-integration-adonis";
export default defineAdonisTenancyConfig({
resolver: (ctx) => ({ id: ctx.subdomains.tenant ?? "" }),
});Register the provider, then add the tenancy middleware to your router (the init scaffold does both).
Each request resolves its tenant and runs scoped, so your Lucid models are automatically isolated - no
per-query tenant filters:
// inside a controller - already tenant-scoped
const orders = await Order.all();How it behaves
- The middleware opens a tenant scope for the request; Lucid queries run scoped through the adapter.
- Resolution failures fail closed with the right status before your controller runs.
- Central-scope work (cross-tenant admin) is opened explicitly, never by accident.