cel2sql Examples
This directory contains examples demonstrating various features and use cases of cel2sql.
Available Examples
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
Getting Started
Each example directory contains:
main.go - The runnable example code
README.md - Detailed documentation and explanation
Prerequisites
- Go 1.24 or later
- For the LoadTableSchema example: PostgreSQL database (optional for static demo)
Running Examples
Navigate to any example directory and run:
go run main.go
Example Progression
We recommend exploring the examples in this order:
- Basic - Start here to understand the core concepts
- LoadTableSchema - Learn about dynamic schema loading and database integration
Key Concepts Demonstrated
- 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
Adding New Examples
When adding new examples:
- Create a new subdirectory under
examples/
- Include a
main.go with a complete, runnable example
- Add a comprehensive
README.md explaining the example
- Update this main README to include the new example
- Ensure the example follows the established patterns and includes proper error handling