{"id":43883,"library":"sql-code-generator","title":"sql-code-generator","description":"A CLI tool that generates TypeScript type definitions and typed query functions from SQL schemas and queries, supporting PostgreSQL and MySQL. At version 0.10.1, it's in early development with an oclif-based CLI. Key differentiators: generates both types and executable query functions, works with existing .sql files and .ts files containing SQL strings, and uses a single config file (codegen.sql.yml). Requires peer dependency yesql 3.2.2. Inspired by graphql-code-generator.","status":"active","version":"0.10.1","language":"javascript","source_language":"en","source_url":"https://github.com/ehmpathy/sql-code-generator","tags":["javascript","database","schema","sql","typescript","generator","client","types"],"install":[{"cmd":"npm install sql-code-generator","lang":"bash","label":"npm"},{"cmd":"yarn add sql-code-generator","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-code-generator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for SQL query generation","package":"yesql","optional":false}],"imports":[{"note":"Package is ESM-only; no CommonJS support.","wrong":"const generate = require('sql-code-generator');","symbol":"generate","correct":"import { generate } from 'sql-code-generator';"},{"note":"Generated types are exported from the file specified in the config (`generates.types`).","wrong":"","symbol":"SqlTablePhoto","correct":"import { SqlTablePhoto } from './dao/generated/types';"}],"quickstart":{"code":"// Install\nnpm install --save-dev sql-code-generator yesql\n\n// Create codegen.sql.yml\n/* language: postgres\ndialect: 10.7\nresources:\n  - \"schema/**/*.sql\"\nqueries:\n  - \"src/dao/**/*.ts\"\n  - \"!src/**/*.test.ts\"\ngenerates:\n  types: src/dao/generated/types.ts\n  queryFunctions: src/dao/generated/queryFunctions.ts\n*/\n\n// Run\nnpx sql-code-generator generate","lang":"typescript","description":"Installation, config setup, and running the generator to produce TypeScript types and query functions from SQL schemas."},"warnings":[{"fix":"Pin to exact version in package.json.","message":"Package version 0.x may introduce breaking changes in minor releases.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Install yesql as a dependency: npm install yesql@3.2.2","message":"Missing peer dependency yesql (3.2.2) will cause runtime errors.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure file exists at project root or use --config <path>","message":"Config file must be named codegen.sql.yml in project root, or path must be provided via --config.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.10.1':28 '3.2.2':71 'base':38 'cli':6,39 'client':84 'code':3,76 'codegen.sql.yml':66 'config':64 'contain':57 'databas':79 'definit':12 'depend':69 'develop':33 'differenti':41 'earli':32 'execut':46 'exist':51 'file':53,56,65 'function':16,48 'generat':4,9,42,77,83 'graphql':75 'graphql-code-gener':74 'inspir':72 'javascript':78 'key':40 'mysql':25 'oclif':37 'oclif-bas':36 'peer':68 'postgresql':23 'queri':15,21,47 'requir':67 'schema':19,80 'singl':63 'sql':2,18,52,58,81 'sql-code-gener':1 'string':59 'support':22 'tool':7 'ts':55 'type':11,14,44,85 'typescript':10,82 'use':61 'version':27 'work':49 'yesql':70","created_at":"2026-06-05T17:01:56.382919+00:00","updated_at":"2026-06-05T17:01:56.382919+00:00","problems":[{"fix":"Run: npm install yesql@3.2.2","cause":"Missing peer dependency yesql.","error":"Cannot find module 'yesql'"},{"fix":"Create codegen.sql.yml in the project root or specify with --config.","cause":"The required codegen.sql.yml file is missing.","error":"Error: No config file found"}],"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":"https://github.com/ehmpathy/sql-code-generator","github":"https://github.com/ehmpathy/sql-code-generator","docs":null,"changelog":null,"pypi":null,"npm":"sql-code-generator","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"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}}