Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mapper Laravel Package

atlas/mapper

Atlas.Mapper is a lightweight data mapper for Atlas, used as the core of Atlas.Orm or standalone. Create a MapperLocator with PDO params, fetch mappers by class, and work with Records via select, fetch, insert, update, delete, and persist.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strengths:

    • Decoupled Data Access: Atlas.Mapper provides a clean separation between business logic and database operations, aligning with the Repository Pattern and Active Record paradigms. This is particularly valuable for Laravel applications where domain-driven design (DDD) or layered architecture is preferred.
    • Relationship Management: Supports one-to-one, one-to-many, and many-to-many relationships with cascading deletes, eager loading (joinWith), and automatic foreign key management. This reduces boilerplate for complex ORM-like operations.
    • Performance Optimizations: Includes benchmarks and fixes for large datasets (e.g., many-to-many optimizations in v1.3.3), making it suitable for high-throughput applications.
    • Extensibility: Supports custom MapperEvents for query modification (e.g., logging, caching) and integrates with Atlas.Table for SQL generation.
  • Weaknesses:

    • Not a Full ORM: Lacks built-in migrations, schema management, or query builder features (unlike Eloquent). Requires manual PDO setup or integration with Atlas.Cli.
    • Code Generation Dependency: Relies on Atlas.Cli to generate mapper classes, adding a build step and potential versioning complexity.
    • Learning Curve: Requires understanding of Atlas’s ecosystem (e.g., Record, Table, MapperLocator) and deviates from Laravel’s Eloquent conventions.

Integration Feasibility

  • Laravel Compatibility:
    • Can coexist with Eloquent but requires manual mapping between Atlas.Mapper’s Record objects and Laravel’s Model classes (e.g., via accessors/mutators or a facade layer).
    • PDO Integration: Works with Laravel’s database connections (via DB::connection()->getPdo()), but lacks native Laravel service provider support.
    • Event System: Can leverage Laravel’s event system (e.g., Model::saved) to trigger Atlas.Mapper events, but requires custom glue code.
  • Migration Path:
    • Incremental Adoption: Start with read-heavy operations (e.g., fetchRecords()) in service layers, gradually replacing Eloquent queries.
    • Hybrid Approach: Use Atlas.Mapper for complex relationships and Eloquent for simpler CRUD, with a service layer abstracting the difference.
    • Testing: Existing Laravel test suites (e.g., Pest/PHPUnit) can test Atlas.Mapper via its Record objects, but mocking may require additional setup.

Technical Risk

  • Breaking Changes:
    • Atlas.Cli Dependency: If Atlas.Cli evolves (e.g., mapper class naming conventions), existing generated mappers may need regeneration.
    • BC Breaks: v1.0.0-beta2 introduced changes to joinWith() syntax, which could affect existing queries.
  • Performance Overhead:
    • N+1 Queries: Without joinWith(), relationships may trigger additional queries. Mitigate with eager loading or caching.
    • Memory Usage: Large RecordSet operations (e.g., many-to-many) could strain memory. Monitor with Atlas’s benchmarking tools.
  • Debugging Complexity:
    • Stack Traces: Atlas’s event system may obscure Laravel’s exception handling. Use try-catch blocks with custom logging.
    • IDE Support: Limited PHPStorm metadata (added in v1.0.0-beta2) may require manual type hints for full IDE integration.

Key Questions

  1. Use Case Alignment:
    • Is Atlas.Mapper’s relationship-first approach a better fit than Eloquent for your domain (e.g., complex hierarchies, polymorphic associations)?
  2. Team Familiarity:
    • Does the team have experience with code-generated mappers or Atlas’s ecosystem? If not, budget for ramp-up time.
  3. Laravel Ecosystem Trade-offs:
    • Are you willing to forgo Laravel’s built-in features (e.g., migrations, Scout, Nova) for Atlas.Mapper’s capabilities?
  4. Long-Term Maintenance:
    • Is the Atlas project actively maintained? (Last release: 2023-09-25; no dependents suggest niche adoption.)
  5. Hybrid Strategy:
    • How will you handle cases where Atlas.Mapper and Eloquent both access the same tables? (e.g., transaction management, connection sharing)

Integration Approach

Stack Fit

  • Laravel Integration Points:
    • Database Layer: Replace Eloquent’s Model::query() with Atlas.Mapper’s Mapper::select() or fetchRecords().
    • Service Layer: Use Atlas.Mapper for business logic operations (e.g., insert(), update()) while keeping Eloquent for API responses.
    • Events: Bridge Atlas.Mapper’s MapperEvents to Laravel’s Model::dispatch() for consistency.
  • Compatibility:
    • PDO: Atlas.Mapper works with Laravel’s PDO connections (e.g., DB::connection('mysql')->getPdo()).
    • Collections: Convert RecordSet to Laravel Collections via ->toArray() or custom iterators.
    • Validation: Use Laravel’s validator with Atlas.Mapper’s Record objects by casting to arrays or using accessors.
  • Tooling:
    • Atlas.Cli: Required for generating mapper classes. Integrate into Laravel’s build process (e.g., post-install-cmd in composer.json).
    • Migrations: Use Laravel Migrations for schema changes; Atlas.Mapper handles data operations.

Migration Path

  1. Phase 1: Read Operations
    • Replace Eloquent queries with Atlas.Mapper’s fetchRecords() or select().
    • Example:
      // Before (Eloquent)
      $users = User::with('posts')->get();
      
      // After (Atlas.Mapper)
      $userMapper = app()->make(UserMapper::class);
      $users = $userMapper->fetchRecords()->joinWith('posts')->execute();
      
  2. Phase 2: Write Operations
    • Replace create(), update(), delete() with Atlas.Mapper’s methods.
    • Example:
      // Before
      User::create(['name' => 'John']);
      
      // After
      $user = $userMapper->newRecord(['name' => 'John']);
      $userMapper->persist($user);
      
  3. Phase 3: Relationships
    • Migrate complex relationships (e.g., many-to-many) to Atlas.Mapper’s joinWith() and persist().
    • Example:
      $userMapper->joinWith('posts')->fetchRecord($userId);
      
  4. Phase 4: Hybrid Layer
    • Create a MapperService facade to abstract differences between Atlas.Mapper and Eloquent:
      class MapperService {
          public function getUser($id) {
              return (new UserMapper())->fetchRecord($id)->toModel();
          }
      }
      

Compatibility

  • Data Mapping:
    • Use accessors/mutators to convert between Record and Model:
      class UserMapper extends Mapper {
          public function toModel(Record $record): User {
              return User::create($record->toArray());
          }
      }
      
  • Transactions:
    • Wrap Atlas.Mapper operations in Laravel transactions:
      DB::transaction(function () {
          $userMapper->persist($user);
      });
      
  • Caching:
    • Leverage Laravel’s cache (e.g., Cache::remember) around Atlas.Mapper’s fetchRecords().

Sequencing

  1. Generate Mappers:
    • Run Atlas.Cli to generate mapper classes (e.g., php atlas generate:mapper User).
  2. Set Up Locator:
    • Configure MapperLocator in a Laravel service provider:
      $this->app->singleton(MapperLocator::class, function () {
          return MapperLocator::new('mysql://user:pass@localhost/db');
      });
      
  3. Replace Queries:
    • Start with non-critical endpoints (e.g., admin panels) to test Atlas.Mapper.
  4. Monitor Performance:
    • Compare query execution times and memory usage with existing Eloquent operations.
  5. Rollback Plan:
    • Maintain a feature flag to toggle between Atlas.Mapper and Eloquent during migration.

Operational Impact

Maintenance

  • Pros:
    • Reduced Boilerplate: Atlas.Mapper handles relationships, validation (via Record), and SQL generation.
    • Consistent Patterns: Enforces a single way to interact with data (vs. Eloquent’s query builder + accessors).
  • Cons:
    • Generated Code: Mappers must be regenerated if Atlas.Cli or Atlas.Mapper updates. Version control generated files.
    • Dependency Management: Atlas.Mapper’s MIT license is permissive, but Atlas.Cli’s maintenance status should be monitored.
    • Debugging: Complex relationship queries may require deep dives into Atlas’s source (e.g., joinWith() nesting).

Support

  • Documentation Gaps:
    • Limited official docs; rely on README, changelog, and tests. Consider writing internal runbooks
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc