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

tradukisto

v0.0.11

Published

Generate Typescript types and Zod schemas for SQL queries

Readme

Tradukisto

Generate Typescript types and Zod schemas for SQL queries

NPM Version

Tradukisto is a tool for generating Typescript types and Zod schemas for arbitrary SQL queries based on the Schema of a live Postgres database, plus some basic templating utilities.

Disclaimer

This library is currently in early development and may contain bugs, incomplete features, or breaking changes without notice. It is not yet production-ready and should be used with caution. Use of this library is at your own risk. The author accepts no responsibility for any data loss, corruption, or other damages that may occur as a result of using this software. By using this library, you acknowledge that you understand these risks.

Installation

npm install tradukisto or yarn add tradukisto

Usage

Run Tradukisto with npx tradukisto. You can optionally pass in the name of a config file to use as the first argument npx tradukisto tradukisto.config.json. If no config file is specified, Tradukisto will try to read ./tradukisto.config.json before falling-back to the default config.

The connection string for your database must be in an environment variable (by default DATABASE_URL). If you store your environment variables in a .env file you can run Tradukisto using a tool such as env-cmd:

npx env-cmd -X tradukisto tradukisto.config.json

Tradukisto uses glob from node:fs/promises internally which way cause an "ExperimentalWarning" error message in some Node versions. This warning can be silenced with npx --node-options='--no-warnings=ExperimentalWarning' tradukisto.

Configuration

Tradukisto can optionally use a JSON config file. The default values are shown below:

{
    // List of SQL input files using glob syntax. Can be a string or a string[].
    "files": "src/**/*.sql",
    // The name of the environment variable containing the Postgres connection string
    "connectionVariableName": "DATABASE_URL",
    // The maximum stack depth for partial expansions
    "partialStackDepth": 100,
    // Generate zod schemas for input and output types
    "zod": true,
}

Watch mode

Start tradukisto in watch mode by setting the WATCH environment variable to any truthy value:

WATCH=true npx tradukisto

Note that watch mode watches files, but you'll still need to manually restart after making database schema changes.

SQL files

In general, your SQL files should start with a @repo declaration to name the output. The repo name should start with an upper-case letter A-Z, followed by 0 or more upper- or lower-case letters, numbers, or underscores:

-- @repo UsersRepo

All SQL queries must be named by a @query declaration. The query name should start with a lower-case letter a-z, followed by 0 or more upper- or lower-case letters, numbers, or underscores:

-- @query getAllUsers
SELECT * FROM users

Arguments should be named and prefixed with a colon. Where possible, Tradukisto will automatically infer the types of parameters, but you can also explicitly cast the parameter to be sure:

-- @query getUserById
SELECT * FROM users WHERE id = :id::TEXT

By default, parameters must be defined and cannot be null. The make a nullable parameter, simply add an underscore to the end of the name. The underscore will not be in the name in the generated typescript; it just tells Tradukisto to make the parameter nullable:

-- @query getUserById
SELECT * FROM users WHERE status = COALESCE(:status_::INTEGER, 2)

Section of SQL that you wish to reuse may be defined using @partial. Note that the replacement is text-based rather than AST-based.

-- @partial verifiedUsersFilter(user_table, confirmations_table)
user_table.verified IS TRUE AND confirmations_table.confirmed IS TRUE

-- @query getVerifiedUsers
SELECT u.*
FROM users u
JOIN user_confirmations uc ON u.id = uc.user_id
WHERE verifiedUsersFilter(u, uc)

You can include other SQL files with @include which takes a relative path. Note that this only includes partials into the current file, not queries or repo declarations:

-- @include ../helpers.sql

License

Tradukisto is free software under the GNU AGPLv3. See the LICENSE file for details.

Note on Generated Output

While Tradukisto is licensed under the AGPLv3, any SQL, Typescript or other code generated by you through the use of this library is not considered part of the library itself and is not subject to the AGPLv3. You are free to license, use, and distribute generated output under terms of your own choosing.