{"id":43968,"library":"sql-typechecker","title":"SQL-Typechecker","description":"SQL-Typechecker is a CLI tool (v0.1.0) written in TypeScript that parses PostgreSQL DDL and SQL function files, performs type-checking beyond what PostgreSQL natively offers, and generates TypeScript type definitions including branded types. It aims to provide rigorous type-checking for SQL functions and supports nested JSON outputs, branded types (newtypes), and a subset of PostgreSQL syntax. The project is under active development but has been used in production for years. It differentiates from tools like pgtyped by not relying on PostgreSQL’s own type-checker and by generating branded types.","status":"active","version":"0.1.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install sql-typechecker","lang":"bash","label":"npm"},{"cmd":"yarn add sql-typechecker","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-typechecker","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime dependency for date/time type handling (peer dependency, required).","package":"@js-joda/core","optional":false}],"imports":[{"note":"The tool is invoked as a CLI command, not imported as a library.","wrong":"sql-typechecker --dir ./sql --out ./ts (if not installed globally)","symbol":"CLI usage","correct":"npx sql-typechecker --dir ./sql --out ./ts"},{"note":"Types are generated in an output file (e.g., types.ts). They are not exported from the package itself.","wrong":"import { customer_id } from 'sql-typechecker';","symbol":"Generated types (e.g., customer_id)","correct":"import { customer_id } from './out/types';\nconst id: customer_id = 42 as customer_id;"},{"note":"Generated functions are ESM exports from the output file. Use dynamic import or configure TypeScript for ESM.","wrong":"const { my_function } = require('./out/out');","symbol":"Generated function (e.g., my_function)","correct":"import { my_function } from './out/out';\nconst result = await my_function(pool, {});"},{"note":"Pool comes from the pg library; sql-typechecker only uses it in generated function signatures.","wrong":"import { Pool } from 'sql-typechecker';","symbol":"TypeScript types for Pool","correct":"import { Pool } from 'pg';\nconst pool = new Pool();"}],"quickstart":{"code":"mkdir -p ./sql\necho 'CREATE TABLE users (\n  id int8 NOT NULL PRIMARY KEY,\n  name text\n);' > ./sql/schema.sql\necho 'CREATE FUNCTION get_users() RETURNS SETOF record AS $$\n  SELECT id, name\n    FROM users\n$$ LANGUAGE sql;' > ./sql/functions.sql\nnpx sql-typechecker --dir ./sql --out ./sql-generated\ncat ./sql-generated/out.ts\n# Output includes:\n# async function get_users(pool: Pool, args: {}): Promise<{ id: number; name: string | null }[]>","lang":"typescript","description":"Shows minimal usage: create a SQL schema file and a function file, run sql-typechecker, and view the generated TypeScript types."},"warnings":[{"fix":"Run 'npm install @js-joda/core' before using sql-typechecker.","message":"Peer dependency @js-joda/core is required but not automatically installed.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Simplify SQL functions or check the list of supported syntax in the documentation. Avoid plpgsql functions as they are not supported.","message":"The tool only supports a subset of PostgreSQL syntax; complex functions may fail to parse.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use the '--out' flag to specify a separate output directory to avoid conflicts.","message":"Generated function names may collide with existing exports; output file is overwritten each run.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Pin to a specific version in package.json (e.g., \"sql-typechecker\": \"0.1.0\").","message":"No official deprecations yet; breaking changes may occur between minor versions before v1.0.","severity":"deprecated","affected_versions":"<1.0.0"}],"env_vars":null,"search_vec":"'activ':69 'aim':41 'beyond':27 'brand':38,56,98 'check':26,47 'checker':94 'cli':9 'ddl':18 'definit':36 'develop':70 'differenti':80 'file':22 'function':21,50 'generat':33,97 'includ':37 'javascript':100 'json':54 'like':83 'nativ':30 'nest':53 'newtyp':58 'offer':31 'output':55 'pars':16 'perform':23 'pgtype':84 'postgresql':17,29,63,89 'product':76 'project':66 'provid':43 'reli':87 'rigor':44 'sql':2,5,20,49 'sql-typecheck':1,4 'subset':61 'support':52 'syntax':64 'tool':10,82 'type':25,35,39,46,57,93,99 'type-check':24,45,92 'typecheck':3,6 'typescript':14,34,101 'use':74 'v0.1.0':11 'written':12 'year':78","created_at":"2026-06-05T17:02:20.538446+00:00","updated_at":"2026-06-05T17:02:20.538446+00:00","problems":[{"fix":"Install the peer dependency: npm install @js-joda/core","cause":"Missing peer dependency @js-joda/core.","error":"Error: Cannot find module '@js-joda/core'"},{"fix":"Rewrite the function to use supported constructs (see documentation) or avoid using unsupported features like plpgsql blocks.","cause":"The SQL function uses syntax not yet supported by sql-typechecker.","error":"Error: Unsupported SQL syntax at line X: ..."},{"fix":"Ensure a SQL DDL file exists in the input directory, or use the '--dsn' flag to specify a connection string for dynamic schema extraction.","cause":"Missing or misnamed schema file; the tool expects a file (default name schema.sql) or use --dsn flag.","error":"Error: Could not find DDL file (schema.sql) in directory ./sql"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"sql-typechecker","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}