Commit Graph

16 Commits

Author SHA1 Message Date
4acce07823 Add comprehensive unit tests for sqlite-serve module
Test Suite: 19 tests covering all core functionality

Configuration Tests:
- test_module_config_default: Verify default initialization
- test_module_config_merge: Test config inheritance
- test_module_config_merge_preserves_existing: Ensure existing values not overwritten
- test_main_config_default: Global config initialization
- test_main_config_merge: Global config inheritance

Query Execution Tests:
- test_execute_query_empty_db: Error handling for missing database
- test_execute_query_with_memory_db: Basic SELECT query
- test_execute_query_with_positional_params: Positional ? parameters
- test_execute_query_with_named_params: Named :name parameters
- test_execute_query_multiple_named_params: Multiple named params (order-independent)
- test_execute_query_with_like_operator: LIKE operator with parameters
- test_execute_query_empty_results: Query returning no rows
- test_execute_query_data_types: All SQLite types (INTEGER, TEXT, REAL, BLOB, NULL)

Template System Tests:
- test_load_templates_from_nonexistent_dir: Graceful handling of missing directories
- test_load_templates_from_dir: Auto-discovery of .hbs files
- test_template_rendering_with_results: Handlebars rendering with data
- test_template_override_behavior: Template re-registration

Parameter Handling Tests:
- test_named_params_parsing: Parameter syntax parsing logic
- test_has_named_params: Detection of named vs positional params

Test Coverage:
✓ Configuration management and merging
✓ SQL query execution (positional and named params)
✓ Data type conversion (INTEGER, TEXT, REAL, BLOB, NULL)
✓ Template loading and rendering
✓ Error handling
✓ Edge cases (empty results, missing files, etc.)

All tests pass. Module verified working in production.
2025-11-15 15:24:56 -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
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