{"id":44044,"library":"tiposaurus-rex","title":"Tiposaurus Rex","description":"CLI tool that generates TypeScript types from annotated MySQL SQL files. v1.0.0. Designed for teams wanting raw SQL with type safety without an ORM. Generates typed interfaces for query results and parameters, SQL constants, and optional execution helpers. MySQL-focused, uses Handlebars templates, supports watch mode. Compared to alternatives like pgtyped or sql-ts, provides explicit annotation-based configuration and built-in mysql2 integration.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/e2cabral/tiposaurus-rex","tags":["javascript","typescript","sql","mysql","code-generator","types","orm"],"install":[{"cmd":"npm install tiposaurus-rex","lang":"bash","label":"npm"},{"cmd":"yarn add tiposaurus-rex","lang":"bash","label":"yarn"},{"cmd":"pnpm add tiposaurus-rex","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required at runtime for generated helper functions which use mysql2's execute method with named placeholders","package":"mysql2","optional":true}],"imports":[{"note":"Generated interfaces are TypeScript types and cannot be used with require. Output files contain types and values.","wrong":"const FindUserByIdResult = require('./generated/find-user')","symbol":"FindUserByIdResult","correct":"import { FindUserByIdResult } from './generated/find-user'"},{"note":"Query constants are generated as camelCase derived from the SQL annotation @name. Interface names start with uppercase.","wrong":"import { FindUserByIdQuery } from './generated/find-user'","symbol":"findUserByIdQuery","correct":"import { findUserByIdQuery } from './generated/find-user'"},{"note":"For runtime execution of generated queries, use the promise-based mysql2/promise with namedPlaceholders:true. CommonJS require works but lacks promise support.","wrong":"const mysql = require('mysql2')","symbol":"mysql","correct":"import mysql from 'mysql2/promise'"}],"quickstart":{"code":"// 1. Install\nnpm install -D tiposaurus-rex\n\n// 2. Create src/queries/find-user.sql with:\n/*\n  @name FindUserById\n  @description Fetch a single user\n  @param userId: number\n  @returnType FindUserByIdResult\n  @returnSingle true\n*/\nSELECT id, email, first_name AS firstName, is_active AS isActive FROM users WHERE id = :userId;\n\n// 3. Generate\nnpx tiposaurus generate\n\n// 4. Use in code\nimport mysql from 'mysql2/promise';\nimport { findUserByIdQuery, FindUserByIdResult } from './generated/find-user';\n\nasync function getUser(id: number) {\n  const pool = mysql.createPool({\n    host: 'localhost',\n    user: 'root',\n    password: process.env.DB_PASSWORD ?? '',\n    database: 'app_db',\n    namedPlaceholders: true,\n  });\n  const [rows] = await pool.execute(findUserByIdQuery, { userId: id });\n  const users = rows as FindUserByIdResult[];\n  return users[0];\n}","lang":"typescript","description":"Setup, generate types from annotated SQL, and execute a typed query using mysql2/promise with named placeholders."},"warnings":[{"fix":"Add tiposaurus.config.json to .gitignore, use environment variables or CI secrets.","message":"Config file tiposaurus.config.json may contain database credentials. Do not commit to version control.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure mysql2 connection options include { namedPlaceholders: true } or use raw SQL constants without helpers.","message":"Generated helper functions expect mysql2 connection with namedPlaceholders: true. Using other database drivers or different placeholder style will fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure SQL files have properly formatted annotations with @name and @param keywords.","message":"Annotations (@name, @param) must follow exact syntax. Missing @name will not generate function exports.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use only with MySQL databases. For other databases, consider alternatives like pgtyped.","message":"Only MySQL is supported. Using PostgreSQL or SQLite will produce incorrect type inference (e.g., boolean vs integer).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Restart watch mode manually if changes are not detected, or check file system permissions.","message":"Watch mode may have file watching issues on certain filesystems (e.g., Windows Subsystem for Linux).","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'altern':52 'annot':10,62 'annotation-bas':61 'base':63 'built':67 'built-in':66 'cli':3 'code':76 'code-gener':75 'compar':50 'configur':64 'constant':36 'design':15 'execut':39 'explicit':60 'file':13 'focus':43 'generat':6,27,77 'handlebar':45 'helper':40 'integr':70 'interfac':29 'javascript':71 'like':53 'mode':49 'mysql':11,42,74 'mysql-focus':41 'mysql2':69 'option':38 'orm':26,79 'paramet':34 'pgtype':54 'provid':59 'queri':31 'raw':19 'result':32 'rex':2 'safeti':23 'sql':12,20,35,57,73 'sql-ts':56 'support':47 'team':17 'templat':46 'tiposaurus':1 'tool':4 'ts':58 'type':8,22,28,78 'typescript':7,72 'use':44 'v1.0.0':14 'want':18 'watch':48 'without':24","created_at":"2026-06-05T17:02:42.340169+00:00","updated_at":"2026-06-05T17:02:42.340169+00:00","problems":[{"fix":"Run 'npm install -D tiposaurus-rex' first, then use 'npx tiposaurus generate'.","cause":"Package not installed or not in PATH.","error":"npx: command not found: tiposaurus"},{"fix":"Check tiposaurus.config.json db settings, start MySQL server, verify credentials.","cause":"MySQL database not running or config has wrong host/port/credentials.","error":"Error: Connection refused to database"},{"fix":"Run 'npx tiposaurus generate' to produce files, and verify outputDir in config matches the import path.","cause":"Generated output directory not created or import path mismatch.","error":"Cannot find module './generated/find-user'"},{"fix":"Import from 'mysql2/promise' instead of 'mysql2'.","cause":"Using mysql2 callback-based client instead of promise-based.","error":"TypeError: pool.execute is not a function"}],"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/e2cabral/tiposaurus-rex#readme","github":"https://github.com/e2cabral/tiposaurus-rex","docs":null,"changelog":null,"pypi":null,"npm":"tiposaurus-rex","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}}