The Snaplet Config File
Customize how Snaplet works by adding a snaplet.config.ts
file in the root of your project.
A valid Snaplet config file exports its configuration using the default export, using the recommended defineConfig
helper:
The configuration object is broken down into multiple sections, following our core concepts, each with their own set of options.
Introspect
There are situations where your database constraints are not enough to fully describe your data model, this is where the introspect
section comes in to allow you to add additional information to help Snaplet understands your database structure.
For example, if you have a table with a relationship to another one, but the foreign key constraint is not defined in the database, you can use the virtualForeignKeys
option to tell Snaplet about it:
Seed
If you don't have access to production data, or if you want to generate a fake dataset for development/testing purposes, you can use the seed
section to define how Snaplet should generate your data.
For an in-depth guide on how to use the seed
section, check out the Seed page.
Capture
If you have access to production data, the following sections will allow you to customize how you want to capture your data.
Select
The select
section allows you to filter which part of your database you want to capture.
For an in-depth guide on how to use the select
section, check out the Select data page.
Transform
The transform
section allows you to apply transformations to your data before it gets captured.
For an in-depth guide on how to use the transform
section, check out the Transform data page.
Subset
The subset
section allows you to capture only a fraction of your data while keeping your relationships intact.
For an in-depth guide on how to use the subset
section, check out the Subset data page.
Type-safe configuration based on your database structure
Snaplet recommends generating your own types based on your database structure to have automatic IntelliSense in your IDE. Editors like VSCode are able to read Snaplet's TypeScript type definitions and provide hints and autocompletion for your configuration.
To generate your own types, use the snaplet config generate
command:
This will generate multiple type declaration files under the .snaplet
folder. You can then import these types in your config file using the triple-slash notation: