Skip to content

TOML Configuration

Jordan Marr edited this page Apr 21, 2024 · 16 revisions
Name                                                       Required Description
[general] Required This section contains general settings.
connection Required The database connection string
output Required A path to the generated .fs output file (relative paths are valid)
namespace Required The namespace of the generated .fs output file
cli_mutable Optional If this argument exists, a [<CLIMutable>] attribute will be added to each record. Defaults to true.
mutable_properties Optional Generates all table records with mutable properties. Defaults to false.
nullable_property_type Optional Generates nullable columns as either "Option" or "Nullable". Defaults to "Option".
[sqlhydra_query_integration] Optional This section contains settings that are used when integrating with SqlHydra.Query.
provider_db_type_attributes Optional This field generates metadata attributes used by SqlHydra.Query. Defaults to true.
table_declarations Optional If true, a table declaration/binding will be generated for each table record that can be used in query for and join clauses. NOTE: This was added in SqlHydra v1.2, so you may need to manually add this field if you are upgrading from an older version.
[readers] Optional This optional section contains settings that apply to generating a HydraReader for your database. (This option should be enabled if you are using the SqlHydra.Query library.)
reader_type Required Generates data readers for each table. You can optionally override the default ADO.NET IDataReader type. Ex: "System.Data.SqlClient.SqlDataReader"
[filters] Optional This optional section applies schema/table filters using globbing patterns.
include Required One or more globbing patterns that specify schemas/tables to include as: "{schema}/{table}"
exclude Required One or more globbing patterns that specify schemas/tables to exclude as: "{schema}/{table}"
restrictions Optional Allows you to provide schema restrictions to the ADO.NET GetSchema method to pre-filter your schema data. (This feature is to help pre-filter very large databases.)

Generating TOML File

The SqlHydra CLI will check for a TOML config file. If not found, it will begin a wizard that will create a TOML file for you. Rather than asking you for each individual configuration file, the wizard will only ask for the required options, and then will ask you to select a "use case" for the generated code. The wizard will choose the base options depending on your selected use case.

Use Case Description
SqlHydra.Query Integration (default) This option generates records that include custom integration for use with SqlHydra.Query including metadata attributes and the HydraReader class. You must reference the SqlHydra.Query package when using this option.
Other data library This option is for generating records that can be used with other data access libraries, including Dapper.FSharp, Donald, Npgsql.FSharp, ADO.NET, and many others. Custom attributes and the HydraReader class will be excluded.
Standalone This option generates the table records and the HydraReader but excludes any custom metadata attributes.

This table shows which features are configured for each use case.

  SqlHydra.Query Integration (Default) Other DB Library Standalone Use
Strongly Typed HydraReader ✔️ ✔️
DbProvider Attributes ✔️
Table Declarations ✔️
CLIMutable Attribute ✔️ ✔️ ✔️

Filtering

Generated tables can be filtered by applying globbing patterns supported by Glob.

All filters are case-sensitive!

Table Filters

Include all tables from the dbo schema:

[filters]
include = [ "dbo/*" ]
exclude = [ ]

Exclude all tables from the prod schema:

Note that at least one include is required (includes are applied first, and then excludes are subtracted).

[filters]
include = [ "*" ]
exclude = [ "prod/*" ]

Include all tables that start with "dev" or "test", and exclude tables that contain "123":

[filters]
include = [ "*/dev*", "*/test*" ]
exclude = [ "*/*123*" ]

Column Filters

All column filter patterns must contain a . to separate the table from the column.

Exclude dbo.Person.FName and dbo.Person.LName columns:

[filters]
include = [ "*.*" ]
exclude = [ "dbo/Person.FName", "dbo/Person.LName" ]

Exclude any column in any schema/table that starts with an _.

[filters]
include = [ "*.*" ]
exclude = [ "*._*" ]

Schema Restrictions

This feature allows you to pass schema restrictions filters to pre-filter the GetSchema query results.

For example, the following restrictions will pre-filter when pulling "Tables", "Views" and "Columns" so that only items in the "SalesLT" schema are returned.

[filters]
include = [ "*" ] 
exclude = [ ]
restrictions = { Tables = [ "SalesLT" ], Views = [ "SalesLT" ], Columns = [ "SalesLT" ] }

NOTES:

  • Please review the "schema restrictions" documentation for the data provider you are using for the expected format.
  • Some configurations require passing a null value in the array. Since TOML doesn't support null, you will need to use an empty string "" instead.
  • "Schema restrictions" are not very configurable. For example, it is not possible to pass more than one schema, table or column, and wildcards are not supported. However, this can be a useful feature for pre-filtering a large database to only include a single schema. For most applications, you should use include and exclude glob patterns to post-filter the queried schemas, tables and columns, as this provides much more flexibility.