Commit Graph

13 Commits

Author SHA1 Message Date
7a169e34d5 Add parameterized SQL queries with nginx variables
New Feature: sqlite_param Directive
- Allows passing nginx variables as SQL prepared statement parameters
- Supports query parameters ($arg_name), path captures ($1, $2), headers, etc.
- Safe SQL injection protection via rusqlite prepared statements
- Multiple parameters supported (bound in order to ? placeholders)

Implementation:
- New sqlite_param directive for adding query parameters
- Variable resolution using ngx_http_get_variable() FFI
- UTF-8 validation on all variable values
- Updated execute_query() to accept parameter array
- rusqlite::ToSql parameter binding

Examples:
- Book detail by ID: /book?id=1
- Genre filtering: /genre?genre=Programming
- Year range search: /years?min=2015&max=2024

New Files:
- conf/book_detail.conf: Parameter examples configuration
- server_root/book/detail.hbs: Book detail page template
- server_root/genre/genre.hbs: Genre filter page template
- start_book_detail.sh: Quick start script for params example
- README.md: Comprehensive project documentation
- README_PARAMETERS.md: Parameters feature documentation

Configuration:
- MainConfig now supports global_templates_dir
- ModuleConfig extended with query_params Vec
- Handler resolves variables at request time
- Template paths adjusted for exact location matches

All examples tested and working with both static and parameterized queries.
2025-11-15 15:09:43 -08:00
9132d7485d Add book catalog example with global/local template system
Features:
- Global template configuration (sqlite_global_templates directive)
- Template path resolution relative to location
- Automatic template loading from directories
- Local templates override global templates
- Content handler installation via directive setter

Book Catalog Example:
- Complete working example with 10 technical books
- SQLite database with setup script
- 4 browseable pages (all, programming, databases, computer-science)
- Shared global templates (header, footer, book_card partial)
- Category-specific local templates with unique theming
- Responsive gradient UI design
- Working navigation and filtering

Configuration:
- sqlite_global_templates: HTTP main-level directive for shared templates
- sqlite_template: Location-level directive (sets content handler)
- Template resolution: {doc_root}{uri}/{template_name}
- All .hbs files in directories auto-loaded as partials

Technical improvements:
- Fixed content handler setup (not phase handler)
- Proper HttpModuleMainConf and HttpModuleLocationConf traits
- Template directory scanning and registration
- Error handling with debug logging
2025-11-15 14:52:39 -08:00
63fbee6694 Fix ngx 0.5.0 API compatibility
- Update HttpModule trait implementation to match ngx 0.5.0 API
- Implement HttpModuleLocationConf as separate unsafe trait
- Fix configuration access using Module::location_conf()
- Replace ngx_null_command macro with explicit null command
- Update imports to use correct constant names
- Suppress C FFI naming convention warnings
2025-11-15 14:26:39 -08:00
b28ff2db17 Refactor into generic SQL template framework
- Replace hardcoded Person struct with dynamic column handling
- Add configurable directives: sqlite_db, sqlite_query, sqlite_template
- Support arbitrary SQL queries with any table/column structure
- Create generic execute_query() function returning dynamic JSON data
- Update handler to render templates with configurable paths
- Add build.rs for macOS dynamic linking support
- Fix handler return value to prevent 'header already sent' errors
2025-11-15 13:18:21 -08:00
b4b89d8898 chore: a fix 2025-11-15 13:13:01 -08:00
c39916ee0b chore: make more generic 2025-11-15 13:08:34 -08:00
33ca326f2d chore: ignore .DS_Store 2025-11-15 12:46:45 -08:00
7461431ff5 chore: more improvements 2025-11-15 12:38:36 -08:00
4ff2f8be9b chore: improve things 2025-11-15 12:29:40 -08:00
c209070163 feat: add basic sql uery 2025-11-14 12:33:50 -08:00
77adea7221 chore: more updates 2025-11-14 03:38:19 -08:00
dce6d6ba3b chore: update 2025-11-14 00:18:51 -08:00
4a97d20467 (init) 2025-11-13 23:20:27 -08:00