This datasource is only available for Node.js agents.
Basic usage
Automatic schema introspection
By default, the SQL datasource automatically discovers your database structure when the back-end starts. It extracts:- Tables and views - Each becomes a collection
- Columns - With automatic type detection
- Primary keys - For record identification
- Foreign keys - Converted to relationships
- Indexes - Used for query optimization
information_schema. Ownership roles are recommended.
Introspection is supported for PostgreSQL, MySQL, MariaDB, and Microsoft SQL Server.
What it costs at boot
Introspection reads the whole schema on every boot:- Every table is read, whatever
includeandexcludesay. Those only hide collections after the scan. - Each table costs two catalog queries, queued behind the connection pool (five connections unless you set
pool). - Model building then runs on the event loop of the process hosting the agent.
Configuration options
Connection URI
The connection URI format varies by database:SSL configuration
Control SSL/TLS connection behavior:preferred- Use SSL if available, otherwise unencrypted (default)required- Require SSL, fail if unavailableverify- Require SSL with certificate verificationdisabled- Never use SSLmanual- Custom SSL configuration (advanced)
Schema selection
Specify which database schema to use (PostgreSQL, SQL Server):Connection pooling
Configure connection pool for optimal performance:Read replicas
Distribute read operations across replica databases:SSH tunnel
Connect through an SSH tunnel:SOCKS5 proxy
Route connections through a SOCKS5 proxy:Connection timeout
Set maximum time to establish connection:Soft-deleted records
Display records marked as deleted (soft deletes):deleted_at column) and you want to manage deleted records in Forest.
Caching introspection
Generate the introspection withintrospect(), commit the file as a cache, and pass it to createSqlDataSource to skip the scan at boot. Your runtime credentials then no longer need information_schema access. It’s worth doing on a wide schema or with frequent deploys. On a small schema, the default is fine.
1
Generate the file
Run this on every migration, in the same CI step. It needs no time window:
2
Boot from it
introspection goes in the second argument. The schema key in the first selects the Postgres schema (public by default).Live Query support
Enable SQL-based reporting by setting a connection identifier:Supported databases
Source code
This connector is open source. Browse the code or contribute on GitHub:@forestadmin/datasource-sql.