npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dataform-date

v0.0.6

Published

Offers date range control for Dataform in GCP

Readme

Dataform Date

npm version

Simplify date range control for Dataform and Google Analytics 4.

Getting Started

  1. In Dataform add the dataform-date package to package.json
    "dataform-date":"latest"
  2. In the js block of your SQLX file, require the package:
    js {
    const dates = require("dataform-date");
    }
  3. Call the functions inline e.g.:
    ${dates.range("suffix","20241001","20241010")}

Functions

  • range(date_range_column, start_date, end_date, overwrite)
  • load(date_range_column, start_date, end_date, full_refresh_start_date, full_refresh_end_date)
  • create_table_id(date_override)

range(date_range_column, start_date, end_date, overwrite)

Creates a SQL BETWEEN clause string to filter a date range. Invalid dates like "2024-13-02" will throw an error.

Arguments:

  • date_range_column (string): The name of the date column to filter on.
    • Use "suffix" or "ga4" to filter on _table_suffix (for GA4 partitioned tables), which formats dates as YYYYMMDD.
    • For any other string, it's treated as a regular date column, and dates are formatted as YYYY-MM-DD.
  • start_date (string | number): The start of the date range.
    • As a string: A static date in YYYY-MM-DD or YYYYMMDD format.
    • As a number: A dynamic offset in days from the current date (e.g., -7 for 7 days ago).
    • Defaults to -1 (yesterday) if not provided.
  • end_date (string | number): The end of the date range.
    • Same format as start_date.
    • Defaults to -1 (yesterday) if not provided.
  • overwrite (boolean): Defaults to true. If false, it adds a condition to only select dates that are not already in the target table (...AND ${date_range_column} NOT IN (SELECT DISTINCT ${date_range_column} FROM ${self()})).

Examples:

  • Default (no arguments): Filters _table_suffix for yesterday.
    ${dates.range()}
    -- output: _table_suffix between "<yesterday_YYYYMMDD>" and "<yesterday_YYYYMMDD>"
  • GA4 _table_suffix with dynamic dates: Filters the last 7 days of data.
    ${dates.range("suffix", -7, -1)}
    -- output: _table_suffix between "<7_days_ago_YYYYMMDD>" and "<yesterday_YYYYMMDD>"
  • Custom date column: Filters session_date for the last 3 days.
    ${dates.range("session_date", -3, -1)}
    -- output: session_date between "<3_days_ago_YYYY-MM-DD>" and "<yesterday_YYYY-MM-DD>"
  • Mixed static and dynamic dates: Filters from a fixed date up to yesterday.
    ${dates.range("session_date", "2024-01-01", -1)}
    -- output: session_date between "2024-01-01" and "<yesterday_YYYY-MM-DD>"
  • Disabling overwrite:
    ${dates.range("session_date", -7, -1, false)}
    -- output: session_date between "<7_days_ago_YYYY-MM-DD>" and "<yesterday_YYYY-MM-DD>" and session_date not in (select distinct session_date from ${self()})

load(date_range_column, start_date, end_date, full_refresh_start_date, full_refresh_end_date)

A wrapper around range() to simplify creating incremental tables in Dataform. It generates a date filter that behaves differently for incremental runs vs. full refreshes.

Arguments:

  • date_range_column (string): The date column name (see range() for details).
  • start_date (string | number): The start date for an incremental run.
  • end_date (string | number): The end date for an incremental run.
  • full_refresh_start_date (string | number): The start date for a full refresh.
  • full_refresh_end_date (string | number): The end date for a full refresh.

Example: In your definitions/my_table.sqlx:

config { type: "incremental" }

select * from source_table
where ${dates.load("session_date", -3, -1, "2023-01-01", -1)}

-- For an incremental run, this resolves to:
-- where session_date between "<3_days_ago_YYYY-MM-DD>" and "<yesterday_YYYY-MM-DD>"

-- For a full refresh, this resolves to:
-- where session_date between "2023-01-01" and "<yesterday_YYYY-MM-DD>"

create_table_id(date_override)

Creates a fully-qualified table ID for a specific GA4 daily table (e.g., my_project.my_dataset.events_20241010). The date suffix changes automatically based on the execution date.

Arguments:

  • date_override (string | number):
    • As a string: A static date suffix in YYYYMMDD format.
    • As a number: A dynamic offset in days from the current date.
    • Defaults to -1 (yesterday) if not provided.

Examples: (Assuming dataform.json has defaultDatabase: "my_gcp_project" and defaultSchema: "my_gcp_dataset")

  • Default (yesterday's table):
    ${dates.create_table_id()}
    // output: `my_gcp_project.my_gcp_dataset.events_<yesterday_YYYYMMDD>`
  • Dynamic date (table from 3 days ago):
    ${dates.create_table_id(-3)}
    // output: `my_gcp_project.my_gcp_dataset.events_<3_days_ago_YYYYMMDD>`
  • Static date:
    ${dates.create_table_id("20241001")}
    // output: `my_gcp_project.my_gcp_dataset.events_20241001`

This updated documentation provides a much clearer and more comprehensive guide to using your package.