Welcome to the CQL (Crystal Query Language) examples directory! This collection demonstrates the powerful features and capabilities of the CQL ORM framework through practical, real-world examples.
The examples are organized into logical categories for easy navigation:
🚀 basic/
Simple getting-started examples perfect for newcomers to CQL:
- simple_cache_demo.cr - Basic caching operations and features
- simple_caching_demo.cr - Fundamental caching concepts
- simple_redis_demo.cr - Redis cache integration basics
💾 caching/
Advanced caching examples showcasing CQL's enterprise-grade caching system:
- active_record_cache_demo.cr - ActiveRecord integration with caching
- activerecord_cache_demo.cr - Model-level caching demonstrations
- advanced_caching_example.cr - Complex caching patterns and strategies
- cache_configuration_example.cr - Cache configuration and setup
- redis_cache_demo.cr - Redis backend integration
- per_request_query_cache_demo.cr - Request-scoped query caching
Configuration examples showing how to set up CQL for different environments:
- configuration_showcase.cr - Developer-friendly configuration patterns
- migrator_config_example.cr - Migration system configuration
🗄️ migrations/
Database migration and schema management examples:
- schema_migration_workflow.cr - SQLite migration workflows
- schema_migration_workflow_pg.cr - PostgreSQL migration workflows
- generated_schema.cr - Auto-generated schema examples
Performance monitoring and optimization examples:
- performance_monitoring_example.cr - Comprehensive performance analysis
- logger_report_example.cr - Development debugging with logger reports
Examples showing CQL integration with popular Crystal web frameworks:
- azu_query_cache_demo.cr - Azu framework integration
🎯 blog/
Comprehensive blog application demonstrating all CQL features:
- Complete MVC structure with models, migrations, and seeders
- Advanced query patterns, relationships, and performance monitoring
- Production-ready example showcasing best practices
🛠️ utilities/
Helper modules and utilities used across examples:
- beautify.cr - Console output formatting and styling utilities
Important: Always run examples from the project root directory (not from within the examples/ directory). The examples use relative paths to find the CQL source files.
- Crystal programming language (1.16.3+)
- SQLite3 (for most examples)
- PostgreSQL (for PostgreSQL-specific examples)
- Redis (for Redis caching examples)
-
Interactive Runner (Recommended):
# Run from the project root directory crystal examples/run_examples.cr -
Start with Basic Examples:
# Run from the project root directory crystal examples/basic/simple_cache_demo.cr -
Try the Blog Application:
crystal examples/blog/blog_demo.cr
-
Explore Advanced Caching:
crystal examples/caching/advanced_caching_example.cr
-
Performance Monitoring:
crystal examples/performance/performance_monitoring_example.cr
Start here if you're new to CQL:
basic/simple_cache_demo.cr- Core conceptsblog/blog_demo.cr- Complete application structureconfiguration/configuration_showcase.cr- Setup and configuration
Production-ready patterns and best practices:
blog/- Full MVC application structuremigrations/schema_migration_workflow.cr- Database evolutionperformance/performance_monitoring_example.cr- Monitoring and optimization
Make your application fast and efficient:
caching/advanced_caching_example.cr- Advanced caching strategiescaching/per_request_query_cache_demo.cr- Request-scoped cachingperformance/performance_monitoring_example.cr- Performance analysis
Configuration and deployment examples:
configuration/configuration_showcase.cr- Environment-specific configsmigrations/- Database migration workflowsframework-integration/- Web framework integration
- ✅ Type-safe database operations - Compile-time type checking
- ✅ ActiveRecord pattern - Intuitive model definitions and operations
- ✅ Complex relationships - belongs_to, has_many, has_one, many_to_many
- ✅ Advanced queries - Joins, aggregations, subqueries, raw SQL
- ✅ Database migrations - Version-controlled schema evolution
- ✅ Multiple database support - SQLite, PostgreSQL, MySQL
- 🚀 Enterprise-grade caching - Memory, Redis, fragment, tag-based invalidation
- 📊 Performance monitoring - Real-time query analysis, N+1 detection
- 🔧 Developer-friendly configuration - Environment-based setup
- 🌐 Web framework integration - Kemal, Azu, and others
- 💾 Connection pooling - Efficient database connection management
- 🔒 Transaction management - ACID compliance and rollback safety
All examples demonstrate production-ready patterns:
- Error handling - Comprehensive exception management
- Performance monitoring - Built-in query analysis and optimization
- Security - SQL injection prevention and safe parameter binding
- Scalability - Connection pooling and caching strategies
- Maintainability - Clean architecture and separation of concerns
Each directory contains its own README with detailed explanations and usage instructions. The examples are thoroughly documented with inline comments explaining the concepts and patterns being demonstrated.
Found an issue or want to improve an example? Contributions are welcome! Please ensure any new examples follow the established patterns and include comprehensive documentation.
- CQL Repository - Main CQL repository
- Crystal Language - Crystal programming language
- CQL Documentation - Comprehensive CQL documentation
Ready to explore CQL's powerful features? Start with the basic examples and work your way up to the complete blog application! 🚀