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.
Strengths:
joinWith), and automatic foreign key management. This reduces boilerplate for complex ORM-like operations.MapperEvents for query modification (e.g., logging, caching) and integrates with Atlas.Table for SQL generation.Weaknesses:
Record, Table, MapperLocator) and deviates from Laravel’s Eloquent conventions.Record objects and Laravel’s Model classes (e.g., via accessors/mutators or a facade layer).DB::connection()->getPdo()), but lacks native Laravel service provider support.Model::saved) to trigger Atlas.Mapper events, but requires custom glue code.fetchRecords()) in service layers, gradually replacing Eloquent queries.Record objects, but mocking may require additional setup.joinWith() syntax, which could affect existing queries.joinWith(), relationships may trigger additional queries. Mitigate with eager loading or caching.RecordSet operations (e.g., many-to-many) could strain memory. Monitor with Atlas’s benchmarking tools.try-catch blocks with custom logging.Model::query() with Atlas.Mapper’s Mapper::select() or fetchRecords().insert(), update()) while keeping Eloquent for API responses.MapperEvents to Laravel’s Model::dispatch() for consistency.DB::connection('mysql')->getPdo()).RecordSet to Laravel Collections via ->toArray() or custom iterators.Record objects by casting to arrays or using accessors.post-install-cmd in composer.json).fetchRecords() or select().// Before (Eloquent)
$users = User::with('posts')->get();
// After (Atlas.Mapper)
$userMapper = app()->make(UserMapper::class);
$users = $userMapper->fetchRecords()->joinWith('posts')->execute();
create(), update(), delete() with Atlas.Mapper’s methods.// Before
User::create(['name' => 'John']);
// After
$user = $userMapper->newRecord(['name' => 'John']);
$userMapper->persist($user);
joinWith() and persist().$userMapper->joinWith('posts')->fetchRecord($userId);
class MapperService {
public function getUser($id) {
return (new UserMapper())->fetchRecord($id)->toModel();
}
}
Record and Model:
class UserMapper extends Mapper {
public function toModel(Record $record): User {
return User::create($record->toArray());
}
}
DB::transaction(function () {
$userMapper->persist($user);
});
Cache::remember) around Atlas.Mapper’s fetchRecords().php atlas generate:mapper User).MapperLocator in a Laravel service provider:
$this->app->singleton(MapperLocator::class, function () {
return MapperLocator::new('mysql://user:pass@localhost/db');
});
Record), and SQL generation.joinWith() nesting).How can I help you explore Laravel packages today?