prorm API Reference
    Preparing search index...

    Class ConnectionManager

    Connection Manager class for managing multiple database connections Allows switching between different databases in the same application

    Index
    • get defaultConnection(): string | null

      Get or set the default connection name

      Returns string | null

    • set defaultConnection(name: string | null): void

      Parameters

      • name: string | null

      Returns void

    • Add a new named database connection

      Parameters

      • name: string

        Unique name to identify this connection

      • options: PrormOptions

        Prorm options for the connection

      Returns Promise<Prorm>

      The Prorm instance for the new connection

      // Add a secondary SQLite database
      const manager = new ConnectionManager();
      await manager.addConnection('analytics', {
      dialect: 'sqlite',
      storage: './analytics.db'
      });
    • Get a connection by name

      Parameters

      • name: string

        The connection name

      Returns Prorm | undefined

      The Prorm instance or undefined if not found

      const analyticsDb = manager.getConnection('analytics');
      
    • Check if a connection exists

      Parameters

      • name: string

        The connection name to check

      Returns boolean

      True if the connection exists

      if (manager.hasConnection('analytics')) {
      // Use analytics connection
      }
    • Remove a connection by name

      Parameters

      • name: string

        The connection name to remove

      Returns Promise<boolean>

      True if the connection was removed

      await manager.removeConnection('analytics');
      
    • Get all connection names

      Returns string[]

      Array of connection names

      const names = manager.getConnectionNames();
      // ['main', 'analytics', 'logs']
    • Attach a SQLite database using ATTACH DATABASE This allows querying across multiple SQLite files

      Parameters

      • mainConnectionName: string

        The name of the main connection to attach to

      • alias: string

        The alias to use for the attached database

      • path: string

        Path to the SQLite file to attach

      Returns Promise<void>

      // Attach analytics database to main connection
      await manager.attachDatabase('main', 'analytics', './analytics.db');
      // Now you can query: SELECT * FROM analytics.users
    • Detach a SQLite database

      Parameters

      • mainConnectionName: string

        The name of the main connection

      • alias: string

        The alias of the database to detach

      Returns Promise<void>

      await manager.detachDatabase('main', 'analytics');
      
    • Close all connections

      Returns Promise<void>

      await manager.closeAll();
      
    • Execute a raw query on a specific connection

      Parameters

      • connectionName: string

        The name of the connection to use

      • sql: string

        The SQL query to execute

      • Optionaloptions: {
            raw?: boolean;
            replacements?: Record<string, any>;
            bind?: Record<string, any>;
        }

        Optional query options

      Returns Promise<any>

      Query results

      const results = await manager.query('main', 'SELECT * FROM users');