snapshot
Reference
Configuration

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:

snaplet.config.ts

import { defineConfig } from 'snaplet'
export default defineConfig({
// your configuration options here...
})

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:

snaplet.config.ts

import { defineConfig } from 'snaplet'
export default defineConfig({
introspect: {
virtualForeignKeys: [
{
fkTable: 'public.Post',
targetTable: 'public.User',
keys: [{ fkColumn: 'authorId', targetColumn: 'id' }],
},
],
}
})

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.

snaplet.config.ts

import { defineConfig } from 'snaplet';
export default defineConfig({
select: {
// the archive schema won't be captured
archive: false,
public: {
// the AuditLog table data won't be captured, but its structure will be
AuditLog: 'structure',
},
},
});

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.

snaplet.config.ts

import { copycat } from '@snaplet/copycat'
import { defineConfig } from 'snaplet';
export default defineConfig({
transform: {
public: {
User({ row }) {
return {
// anonymize the email address
email: copycat.email(row.email),
}
},
},
},
});

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.

snaplet.config.ts

import { defineConfig } from 'snaplet';
export default defineConfig({
subset: {
targets: [
{
// capture only 10% of the Post table
table: 'public.Post',
percent: 10,
},
],
},
});

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:

>_ terminal

snaplet config generate

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:

snaplet.config.ts

/// <reference path=".snaplet/snaplet.d.ts" />
import { defineConfig } from 'snaplet'
// defineConfig now has full IntelliSense support based on your database structure
export default defineConfig({
// your configuration options here...
})