This directory contains examples demonstrating various features and use cases of cel2sql.
Demonstrates the fundamental usage of cel2sql:
- Manual schema definition
- CEL environment setup
- Expression compilation and SQL conversion
- Basic PostgreSQL type mappings
Run: cd basic && go run main.go
Demonstrates dynamic schema loading from PostgreSQL databases:
- Connecting to PostgreSQL databases
- Loading table schemas dynamically using
LoadTableSchema - Using loaded schemas in CEL expressions
- Integration testing patterns
Run: cd load_table_schema && go run main.go
Each example directory contains:
main.go- The runnable example codeREADME.md- Detailed documentation and explanation
- Go 1.24 or later
- For the LoadTableSchema example: PostgreSQL database (optional for static demo)
Navigate to any example directory and run:
go run main.goWe recommend exploring the examples in this order:
- Basic - Start here to understand the core concepts
- LoadTableSchema - Learn about dynamic schema loading and database integration
- Schema Definition: Both manual and dynamic schema creation
- Type Safety: CEL type checking with PostgreSQL types
- SQL Generation: Converting CEL expressions to PostgreSQL-compatible SQL
- PostgreSQL Integration: Working with real database connections
- Best Practices: Error handling, resource management, and testing patterns
When adding new examples:
- Create a new subdirectory under
examples/ - Include a
main.gowith a complete, runnable example - Add a comprehensive
README.mdexplaining the example - Update this main README to include the new example
- Ensure the example follows the established patterns and includes proper error handling
- Main README - Project overview and usage
- Contributing Guide - Development setup and testing patterns
- API Documentation - Detailed API reference