60ab81cb1c
* feat: Enhanced BLOB support across all database backends - Add comprehensive BLOB support for all supported databases: * PostgreSQL: BYTEA columns with data URL conversion * MySQL/MariaDB: BLOB columns with data URL conversion * MSSQL: VARBINARY, BIGVARBINARY, BINARY, IMAGE columns * SQLite: BLOB columns with data URL conversion - Create shared data URL conversion functions to eliminate code duplication - Add comprehensive tests for all database types - Update CHANGELOG.md with detailed feature description - All blob data is now consistently converted to data URLs with base64 encoding - Cross-database compatibility ensures identical blob behavior across all backends - Comprehensive testing validates functionality across PostgreSQL, MySQL, MariaDB, MSSQL, and SQLite * update changelog * fmt * fix: Address clippy linter issues - Change blob function parameters from Vec<u8> to &[u8] to avoid unnecessary copying - Use inline format args in data URL construction - Update function calls to borrow parameters correctly - Maintain backward compatibility and functionality * feat: Add smart MIME type detection for BLOB data - Implement automatic MIME type detection based on file signatures (magic bytes) - Support common file formats: PNG, JPEG, GIF, BMP, WebP, SVG, PDF, DOCX, XLSX, PPTX, JSON, XML, ZIP - Automatic fallback to 'application/octet-stream' for unknown formats - Update CHANGELOG.md with comprehensive feature description - Add comprehensive tests for MIME type detection functionality - BLOB data now automatically returns appropriate data URLs: * PNG files: 'data:image/png;base64,...' * PDF files: 'data:application/pdf;base64,...' * SVG files: 'data:image/svg+xml;base64,...' * Unknown files: 'data:application/octet-stream;base64,...' - Improves user experience by providing correct MIME types for downloads and displays - Eliminates need for manual MIME type specification in most cases * refactor: Make MIME type detection more concise - Use bytes.starts_with() for cleaner magic byte detection - Remove verbose comments for each MIME type - Maintain same functionality with cleaner, more readable code - Reduce code duplication and improve maintainability * refactor: Improve MIME type detection with byte strings - Use byte string literals (b"string") for better readability - Remove UTF-8 parsing for text-based formats, use direct byte comparisons - Maintain same functionality with cleaner, more performant code - PNG: b"\x89PNG\r\n\x1a\n" instead of hex arrays - JPEG: b"\xFF\xD8" instead of [0xFF, 0xD8] - Text formats: Direct byte matching without String::from_utf8_lossy - Update all tests to use new byte string format * refactor: Extract MIME type detection into separate module - Create new mime_detection.rs module for better code organization - Move detect_mime_type() function and tests to dedicated module - Update sql_to_json.rs to import from mime_detection module - Remove unused import from functions.rs - Maintain same functionality with improved code structure Benefits: - Better separation of concerns - Improved code organization and maintainability - Easier to extend MIME detection in the future - Cleaner module boundaries File changes: - NEW: src/webserver/database/mime_detection.rs (MIME detection + tests) - MOD: src/webserver/database/mod.rs (add mime_detection module) - MOD: src/webserver/database/sql_to_json.rs (use mime_detection module) - MOD: src/webserver/database/sqlpage_functions/functions.rs (remove unused import) * refactor: Rename mime_detection.rs to blob_to_data_url.rs - Rename module from mime_detection to blob_to_data_url for better clarity - Follow project naming conventions (similar to sql_to_json.rs) - Update all imports and references to use new module name - Maintain same functionality with improved code organization File changes: - RENAMED: src/webserver/database/mime_detection.rs → src/webserver/database/blob_to_data_url.rs - MOD: src/webserver/database/mod.rs (update module declaration) - MOD: src/webserver/database/sql_to_json.rs (update import path) - MOD: src/webserver/database/sqlpage_functions/functions.rs (update import path) * move - Add #[must_use] attribute to detect_mime_type for better usage indication - Replace empty byte check with is_empty() for clarity - Update tests for improved readability with formatted assertions - Remove unnecessary blank lines in sql_to_json.rs Benefits: - Improved code clarity and maintainability - Enhanced test readability * remove old file * refactor: Update sql_to_json.rs to use new blob_to_data_url module - Replace direct call to vec_to_data_uri_value with updated import from blob_to_data_url - Remove deprecated vec_to_data_uri and vec_to_data_uri_value functions for cleaner code - Maintain existing functionality while improving code organization * refactor: Simplify MIME type detection logic in blob_to_data_url.rs - Remove unnecessary empty byte check and streamline conditions for text-based formats - Enhance readability by consolidating checks for XML and JSON formats - Maintain existing functionality while improving code clarity * clippy * Update documentation for BLOB support and data type handling - CHANGELOG.md : details on BLOB support and automatic MIME type detection - Add examples in extensions-to-sql.md illustrating data type conversions and JSON object structure - Update SQL examples in migrations to reflect new BLOB handling capabilities
62 lines
1.7 KiB
YAML
62 lines
1.7 KiB
YAML
# You can easily switch between different databases by changing the value of COMPOSE_PROFILES in the .env file.
|
|
|
|
# possible database connection strings:
|
|
# DATABASE_URL='postgres://root:Password123!@localhost/sqlpage'
|
|
# DATABASE_URL='mssql://root:Password123!@localhost/sqlpage'
|
|
# DATABASE_URL='mysql://root:Password123!@localhost/sqlpage'
|
|
|
|
# Run for instance:
|
|
# docker compose up postgres
|
|
# and in another terminal:
|
|
# DATABASE_URL='db_url' cargo test
|
|
services:
|
|
web:
|
|
build: { context: "." }
|
|
ports:
|
|
- "8080:8080"
|
|
volumes:
|
|
- .:/var/www
|
|
depends_on:
|
|
# mssql: { condition: service_healthy }
|
|
[ "${COMPOSE_PROFILES-postgres}" ]
|
|
environment:
|
|
DATABASE_URL: ${COMPOSE_PROFILES-postgres}://root:Password123!@${COMPOSE_PROFILES:-postgres}/sqlpage${DATABASE_URL_PARAMS:-}
|
|
RUST_LOG: sqlpage=trace
|
|
postgres:
|
|
profiles: ["postgres"]
|
|
ports: ["5432:5432"]
|
|
build: { context: "db-test-setup/postgres" }
|
|
shm_size: 128mb
|
|
environment:
|
|
POSTGRES_USER: root
|
|
POSTGRES_DB: sqlpage
|
|
POSTGRES_PASSWORD: Password123!
|
|
healthcheck:
|
|
test: pg_isready -U root -d sqlpage
|
|
|
|
mysql:
|
|
profiles: ["mysql"]
|
|
ports: ["3306:3306"]
|
|
image: mysql
|
|
environment:
|
|
MYSQL_ROOT_PASSWORD: Password123!
|
|
MYSQL_DATABASE: sqlpage
|
|
|
|
mssql:
|
|
profiles: ["mssql"]
|
|
ports: ["1433:1433"]
|
|
build: { context: "db-test-setup/mssql" }
|
|
healthcheck:
|
|
test: /opt/mssql-tools18/bin/sqlcmd -S localhost -U root -P "Password123!" -Q "SELECT 1" -b -o /dev/null -No
|
|
interval: 10s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 10s
|
|
|
|
mariadb:
|
|
profiles: ["mariadb"]
|
|
ports: ["3306:3306"]
|
|
image: mariadb
|
|
environment:
|
|
MYSQL_ROOT_PASSWORD: Password123!
|
|
MYSQL_DATABASE: sqlpage |