@hipsjs/adonis-multitenancy
TypeScript icon, indicating that this package has built-in type declarations

1.0.12 • Public • Published

AdonisJS Multitenancy

Works with adonis preview v5

Simple multi tenancy for AdonisJS - WIP but functional :)

  • Single database (for now)
  • @isTenant and @belongsToTenant Lucid decorators
  • Caches tenants in memory
  • Errors thrown when tenant not provided
  • Roadmap: query scopes, plug and play middleware, more caching options, multi database

📄 Installation

1. Install using npm or yarn and call ace's invoke

npm i --save @hipsjs/adonis-multitenancy
node ace invoke @hipsjs/adonis-multitenancy

2. Edit config/multitenancy.ts with your configuration.

3. Make sure to register the provider inside .adonisrc.json file.

"providers": [
  "@hipsjs/adonis-multitenancy"
]

4. For TypeScript projects add to tsconfig.json file:

"compilerOptions": {
  "types": [
    "@hipsjs/adonis-multitenancy"
  ]
}

🔧 Usage

Add the @isTenant decorator to your Tenant's Lucid model, in this example we use Organisation as our Tenant, the model will need an id:

import { BaseModel } from '../index'
import { column } from '@adonisjs/lucid/build/src/Orm/Decorators'
import { isTenant } from '../../src/Decorator/isTenant'

@isTenant()
export class Organisation extends BaseModel {
  @column()
  public id: number
}

Add the @belongsToTenant decorator to models that belong to a tenant:

@belongsToTenant()
export class User extends BaseModel {
  public organisationId: number
  public organisation: Organisation
}

⚙️ Development

See package.json scripts

Show Your Support

Please give a if this project helped you!

💕 Contributing

If you have any questions or requests or want to contribute to @hipsjs/adonis-multitenancy or other packages, please write an issue or send in a Pull Request freely.

Package Sidebar

Install

npm i @hipsjs/adonis-multitenancy

Weekly Downloads

1

Version

1.0.12

License

MIT

Unpacked Size

14.8 kB

Total Files

21

Last publish

Collaborators

  • hips1