text: /**
   * TenantManager is used mostly on HANA as a generic wrapper around InstanceManager or similar library.
   * In Sqlite the library provides credentials from options or in-memory by default.
   */
  class TenantManager {
    /**
     * Create empty wrapper object and save options.
     * @param options
     */
    constructor (options) {
      this.options = options
    }
  
    _getTenantDb (host, tenantId) {
      if (host.match(/^.*\.[^/]*$/)) {
        const dotIndex = host.lastIndexOf('.')
        return `${host.substring(0, dotIndex)}_${tenantId}${host.substring(dotIndex)}`
      }
  
      return `${host}_${tenantId}`
    }
  
    /**
     * Get credentials for a service by tenant id.
     * @param tenantId - ignored
     * @returns {*}
     */
    get (tenantId) {
      if (
        this.options.credentials &&
        this.options.credentials.database &&
        this.options.credentials.database !== ':memory:'
      ) {
        return Promise.resolve({ database: this._getTenantDb(this.options.credentials.database, tenantId) })
      }
  
      if (this.options.host && this.options.host !== ':memory:') {
        return Promise.resolve({ database: this._getTenantDb(this.options.host, tenantId) })
      }
  
      return Promise.resolve({ database: ':memory:' })
    }
  }
  
  module.exports = TenantManager
  