template-sqlc




π The Ultimate sqlc Configuration Template - Production-ready, comprehensive sqlc configuration template that works for ALL project types. Takes advantage of EVERY sqlc feature with real working plugins and validated configurations.
Table of Contents
Overview
This project creates professional README templates by analyzing patterns from real-world projects and implementing best practices for documentation. It provides a Go-based generator that creates hierarchical templates for different project types and complexity levels.
Features
-
π‘οΈ Production Safety
CEL validation rules prevent dangerous queries (SELECT *, DELETE without WHERE)
-
β‘ Multi-Database Excellence
SQLite/Turso, PostgreSQL, MySQL - comprehensive support with isolated configurations
-
π¨ Code Generation Mastery
All emit_* options configured with detailed explanations and trade-offs
-
π§ Real Working Plugins
Verified Python, Kotlin, TypeScript plugins with actual SHA256 hashes
-
π Universal Project Support
10+ project type templates from hobby to enterprise scale
-
π Comprehensive Type Overrides
30+ real-world type mapping patterns for domain-specific needs
-
β
Production Validated
Based on analysis of 21+ real projects, sqlc vet verified
-
π― Smart Configuration Management
Environment variables, build tags, conditional compilation support
Quick Start
# Clone this repository
git clone https://github.com/LarsArtmann/template-sqlc.git
cd template-sqlc
# Copy the configuration to your project
cp sqlc.yaml /path/to/your/project/
# Set up example schemas (optional)
make examples
# Generate your Go code
sqlc generate
Installation
Prerequisites
Quick Install
# Install sqlc (macOS)
brew install sqlc
# Install sqlc (Linux)
curl -L https://github.com/kyleconroy/sqlc/releases/latest/download/sqlc_$(uname -s)_$(uname -m).tar.gz | tar -xz -C /usr/local/bin sqlc
# Verify installation
sqlc version
Usage
1. Basic Setup
# Create your project structure
mkdir -p sql/{sqlite,postgres,mysql}/{queries,schema}
# Add your schema files
echo "CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT);" > sql/sqlite/schema/001_users.sql
# Add your queries
echo "-- name: GetUser :one\nSELECT * FROM users WHERE id = ?;" > sql/sqlite/queries/user.sql
# Generate Go code
sqlc generate
2. Using the Template
# Copy the comprehensive configuration
cp sqlc.yaml your-project/
# Uncomment your database configuration
# Edit paths and database URLs
# Validate and generate
sqlc compile # Validate syntax
sqlc generate # Generate Go code
3. Examples
See the examples/ directory for complete, working examples with:
- User management schemas
- Database-specific features (FTS, JSON, Enums)
- Optimized queries and indexes
- Session management patterns
Contributing
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Test your changes:
sqlc compile && sqlc vet
- Commit your changes:
git commit -m 'Add amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
Development Guidelines
- Test thoroughly: Ensure
sqlc compile passes
- Add comments: Explain WHY each setting is chosen
- Consider trade-offs: Document performance/flexibility implications
- Keep universal: Avoid domain-specific hardcoded values
License
This project is licensed under the MIT License - see the LICENSE file for details.
Lars Artmann - https://lars.software
Project Link: https://github.com/LarsArtmann/template-sqlc