minionfactory/raw-hydrator
Raw Hydrator is a small PHP package for turning raw data (arrays/records) into hydrated objects with minimal overhead. Useful for fast mapping of database results or API payloads into DTOs/entities without a full ORM.
with()) would require N+1 queries or manual hydration. Ideal for:
HasFactory, BelongsTo, etc.).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| SQL Injection | High | Enforce prepared statements (package uses PDO). Validate all dynamic SQL inputs. |
| Performance Overhead | Medium | Benchmark against with() + manual hydration. Monitor memory usage for large datasets. |
| Relation Mismatches | High | Rigorously test relation naming and column aliases in raw SQL. |
| Debugging Complexity | Medium | Add logging for raw SQL queries and hydration steps. Use dd() on results for validation. |
| Future Maintenance | Low | Fork if critical fixes are needed (MIT license). |
NULL values, custom casts)?DB::select() + manual hydration or Eloquent’s with() suffice for the use case?Post::with('author', 'comments.user')->get()) with RawHydrator.memory_get_usage())./reports).app/Queries/GetPostsWithRelations.php).Hydrate::raw() helper).Hydrator::map() to handle custom relations or column renaming.Hydrator::hydrate() for post-hydration logic (e.g., appending computed attributes).QueryBuilder::hydrate()).new Model($row) loops.HydrationException.expectException(HydrationException::class).DB::select()->cursor()) for >5K rows.EXPLAIN ANALYZE raw SQL queries in production.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| SQL Syntax Error | App crash | Use try-catch around hydration. |
| Column Mismatch | Silent corruption | Validate columns against model fills. |
| Circular Relations | Infinite loop | Set max_nesting_level in config. |
| Memory Exhaustion | Worker death | Implement chunking or streaming. |
| Schema Drift | Hydration fails | CI checks for schema changes. |
NULL relations).Post with comments.user").SELECT * with aliases").// Hydrates: Post, Comment).How can I help you explore Laravel packages today?