SQLAnvil supports npm-style packages that extend the framework with reusable macros, utility tables, and shared includes. Packages are declared in package.json as dependencies of @sqlanvil/core.
Add a package to your project's package.json:
{
"dependencies": {
"@sqlanvil/core": "latest",
"sqlanvil-scd": "^1.0.0"
}
}Then import it in an includes/ file:
// includes/scd.js
const scd = require("sqlanvil-scd");
module.exports = { scd };Creating a package requires familiarity with the SQLAnvil JavaScript API. A package is an npm module that exports functions using the SQLAnvil session object.
A minimal package looks like:
my-package/
├── index.js ← exports your macros/helpers
├── example.js ← demonstrates usage against a real project
└── README.md
// A macro that creates a standard SCD Type 2 dimension table
function scdType2(tableName, naturalKey, columns) {
return session.publish(tableName, {
type: "incremental",
uniqueKey: [naturalKey],
description: `SCD Type 2 dimension: ${tableName}`
}).query(ctx => `
SELECT
${naturalKey},
${columns.join(",\n ")},
CURRENT_TIMESTAMP AS valid_from,
NULL AS valid_to
FROM ${ctx.ref("staging_" + tableName)}
`);
}
module.exports = { scdType2 };Connect to a data warehouse (BigQuery, Postgres, or Supabase) and run:
sqlanvil compile
sqlanvil run --actions my_dimension_tableOnce ready, publish under your own npm scope:
npm publish --access publicNote: The packages below were written for upstream Dataform (BigQuery-only). They may work for BigQuery-targeted SQLAnvil projects. Postgres/Supabase-specific packages are in development.
- dataform-co/dataform-scd — Slowly Changing Dimensions
- dataform-co/dataform-fivetran-log — Fivetran sync log analysis
- dataform-co/dataform-segment — Segment event modeling
To discuss packages or share your own, open a GitHub Discussion.