Skip to content

How to use more than one database at a time

Kittox supports connecting to multiple databases simultaneously through the database routing feature. Each database can use a different adapter (ADO, FireDAC, DBExpress) and even a different database engine.

Step 1: Define your databases

In Config.yaml, add multiple entries under the Databases node. The entry named Main is used by default:

yaml
Databases:
  Main: ADO
    Connection:
      ConnectionString: >
        Provider=SQLOLEDB.1;User ID=sa;Password=xxx;
        Initial Catalog=PrimaryDB;Data Source=%COMPUTERNAME%
  Reporting: FD
    Connection:
      DriverID: MSSQL
      Server: %COMPUTERNAME%
      Database: ReportingDB
      OSAuthent: Yes

See Databases for the full list of adapters and connection parameters.

Step 2: Route models to databases

Add a DatabaseRouter node to any Model that should use a non-default database:

yaml
ModelName: REPORT_DATA
DatabaseRouter: Static
  DatabaseName: Reporting
Fields:
  ...

All read and write operations for that model will use the Reporting database instead of Main.

Step 3: Route at the view level (optional)

You can also apply database routing at the DataView level. This is useful when the same model should read from different databases in different views:

yaml
Type: Data
Controller: List

MainTable:
  Model: SHARED_MODEL
  DatabaseRouter: Static
    DatabaseName: Reporting

Other places that support routing

Database routing uses the same syntax everywhere a database connection is implied:

LocationUse case
Config.yaml/AuthAuthenticate against a different database
Config.yaml/AccessControlStore access control data in a separate database
DynaList filters in a ListFetch filter values from another database

Custom routers

The Static router covers the most common case (fixed model-to-database mapping). For dynamic rules (e.g. routing based on naming conventions), you can create a custom router by inheriting from TKDatabaseRouter and overriding InternalGetDatabaseName.

See Database Routing for the full reference and advanced examples.

Released under Apache License, Version 2.0.