6 Commits

Author SHA1 Message Date
4f0dc76367 Add JSON/HTML content negotiation and clean up repository
Content Negotiation:
- New content_type.rs: Negotiate JSON vs HTML based on ?format=json
- JSON responses: Direct query results without template rendering
- HTML responses: Full Handlebars template rendering
- Example: /books?format=json returns JSON array

API Endpoints Now Support:
- /books?format=json - All books as JSON
- /book?id=1&format=json - Single book as JSON
- /search?q=Rust&format=json - Search results as JSON
- All existing HTML endpoints continue working

Cleanup:
- Removed old example configs (book_catalog, book_detail, book_named_params, howto)
- Removed old documentation (README_BOOK_CATALOG, README_PARAMETERS)
- Removed old template directories (people, books/all, etc.)
- Removed old template files (header.hbs, footer.hbs, etc.)
- Removed unused files (person.hbs, runit)
- Removed unused method: ParameterBinding::param_name()

Files Kept:
- conf/sqlite_serve.conf (unified production config)
- start.sh (unified start script)
- setup_book_catalog.sh (database setup)
- README.md (main documentation)
- ARCHITECTURE.md (architecture docs)

Build Status:
- 61 tests passing (+2 content type tests)
- 7 benign warnings (unused fields in generated types)
- Zero dead code

JSON verified working, all features functional.
2025-11-15 17:26:00 -08:00
a4a838ad3b Consolidate examples into unified production config with static CSS
- New sqlite_serve.conf: all features on single port 8080
- New zenburn.css: hex color palette, all styles in one cacheable file
- New Zenburn templates: header/footer/card partials
- New start.sh: unified launcher with all endpoint docs
- Removed 3 separate example configs and start scripts

15 files changed, 980 insertions(+), 258 deletions(-)
2025-11-15 16:42:05 -08:00
e016c2421b Add named parameter support for SQL queries
New Feature: Named SQL Parameters
- Supports both positional (?) and named (:name) parameters
- Named parameters are order-independent and more readable
- Syntax: sqlite_param :param_name $variable

Implementation:
- Updated sqlite_param directive to accept 1 or 2 arguments
- ModuleConfig.query_params now stores (name, variable) pairs
- execute_query() detects named vs positional parameters
- Extracted row_to_map closure to avoid type conflicts
- Named params use rusqlite named parameter binding

Examples (Port 8082):
- Book detail: WHERE id = :book_id
- Genre filter: WHERE genre = :genre_name
- Year range: WHERE year >= :min_year AND year <= :max_year
- Title search: WHERE title LIKE '%' || :search_term || '%'
- Rating filter: WHERE rating >= :min_rating

Benefits of Named Parameters:
- Order-independent: params can be in any order in config
- Self-documenting: :book_id is clearer than first ?
- Maintainable: can add/remove params without reordering
- Recommended for all but simplest queries

Configuration:
- conf/book_named_params.conf: Complete named params example
- start_named_params.sh: Quick start script for port 8082

Documentation:
- Added named vs positional comparison in README_PARAMETERS.md
- Updated README.md with named parameter examples
- Documented both syntaxes in directive reference

All examples tested and working with both parameter styles.
2025-11-15 15:20:40 -08:00
775467da51 Rename project from nginx-test to sqlite-serve
- Updated package name in Cargo.toml: nginx-test → sqlite-serve
- Updated library name: libnginx_test.dylib → libsqlite_serve.dylib
- Updated all load_module directives in nginx configs
- Updated build checks in start scripts
- Updated branding in footer template
- Updated project name in all README files

The name 'sqlite-serve' better reflects the module's purpose:
serving dynamic content from SQLite databases via NGINX.
2025-11-15 15:11:44 -08:00
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