About this project
Scythe is a command-line tool that treats SQL as a first-class language. It statically analyzes annotated `.sql` files and generates type-safe database access code—row types, query functions, and type mappings—for ten programming languages (Rust, Python, TypeScript, Go, Java, Kotlin, C#, Elixir, Ruby, PHP, plus plain JavaScript) across ten database engines (PostgreSQL, MySQL, MariaDB, SQLite, DuckDB, CockroachDB, MSSQL, Oracle, Redshift, Snowflake). Generation requires no database connection or network, making it suitable for pre-commit hooks.
Key features include:
- **Type inference**: Nullability is propagated through JOINs, CTEs, window functions, COALESCE, CASE WHEN, and aggregates. Enums, composites, arrays, and JSON map to native language types.
- **Linting and auditing**: 24 lint rules (e.g., UPDATE without WHERE, SELECT *) and 35 audit rules for security and migration safety (e.g., GRANT to PUBLIC, literal passwords, destructive DDL). Output in human, SARIF, or JSON formats.
- **Provenance checking**: `scythe check` verifies that committed generated code matches the SQL it came from, with optional live schema-drift checks against PostgreSQL.
- **Database inspection**: `scythe inspect` performs live health checks (e.g., foreign keys without covering indexes, RLS disabled) for PostgreSQL and MySQL/MariaDB.
- **Flexible output**: Row types as Pydantic, msgspec, dataclasses, Zod schemas, or plain interfaces; type overrides for extension types like ltree, citext, or PostGIS.
- **Annotations**: Beyond `:one`/`:many`, supports `@optional` for conditional filters, `:batch` for bulk operations, and `@returns :grouped` for nested results.
- **Migration from sqlc**: `scythe migrate` converts existing `sqlc.yaml` configurations.
Installation options include cargo, Homebrew, npm, pip, and a GitHub Action. Pre-commit hooks are provided for formatting, linting, auditing, inspecting, generating, and checking. The tool is MIT-licensed and documented at goldziher.github.io/scythe.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.