PHPackages                             bear/projection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. bear/projection

ActiveLibrary[Database &amp; ORM](/categories/database)

bear/projection
===============

Read-optimized query library for BEAR.Resource #\[Embed\]

1.x-dev(3mo ago)10MITPHPPHP ^8.2CI passing

Since Jan 25Pushed 3mo agoCompare

[ Source](https://github.com/bearsunday/BEAR.Projection)[ Packagist](https://packagist.org/packages/bear/projection)[ RSS](/packages/bear-projection/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

BEAR.Projection
===============

[](#bearprojection)

Read-optimized query library for BEAR.Resource `#[Embed]`

Overview
--------

[](#overview)

BEAR.Projection implements the [BDR Pattern](docs/BDR_PATTERN.md) for the Read side, providing `query://` scheme resources designed for `#[Embed]`. A companion to [Ray.MediaQuery](https://github.com/ray-di/Ray.MediaQuery).

### Features

[](#features)

- **Embed-first design** - Optimized for `#[Embed]` in ResourceObject
- **Parallel SQL execution** - Multiple `#[Embed]` queries run concurrently
- **DI-powered Factory** - Inject dependencies for data transformation

Requirements
------------

[](#requirements)

- PHP 8.2+
- MySQL (uses mysqli for async query execution, not PDO)

Installation
------------

[](#installation)

```
composer require bear/projection
```

Usage
-----

[](#usage)

### 1. Define a Projection

[](#1-define-a-projection)

```
namespace MyApp\Projection;

final class UserProfile
{
    public function __construct(
        public readonly string $id,
        public readonly string $name,
        public readonly int $age,
        public readonly string $avatarUrl,
    ) {
    }
}
```

### 2. Create a Factory with DI

[](#2-create-a-factory-with-di)

Factory can inject dependencies for data transformation and validation:

```
namespace MyApp\Projection;

final class UserProfileFactory
{
    public function __construct(
        private readonly AgeCalculator $ageCalculator,
        private readonly ImageUrlResolver $imageResolver,
    ) {
    }

    public function __invoke(
        string $id,
        string $name,
        string $birthDate,
        string $avatarPath,
    ): UserProfile {
        return new UserProfile(
            id: $id,
            name: $name,
            age: $this->ageCalculator->fromBirthDate($birthDate),
            avatarUrl: $this->imageResolver->resolve($avatarPath),
        );
    }
}
```

### 3. Write the SQL Query

[](#3-write-the-sql-query)

```
-- var/sql/query/user_profile.sql
SELECT id, name, birth_date, avatar_path FROM users WHERE id = :id
```

### 4. Configure the Module

[](#4-configure-the-module)

```
use BEAR\Projection\Module\ProjectionModule;

class AppModule extends AbstractModule
{
    protected function configure(): void
    {
        $this->install(new ProjectionModule(
            sqlDir: __DIR__ . '/../var/sql/query',
            projectionNamespace: 'MyApp\\Projection\\',
        ));
    }
}
```

### 5. Embed in Resource

[](#5-embed-in-resource)

```
use BEAR\Resource\Annotation\Embed;
use BEAR\Resource\ResourceObject;

class User extends ResourceObject
{
    #[Embed(rel: 'profile', src: 'query://self/user_profile{?id}')]
    #[Embed(rel: 'orders', src: 'query://self/user_orders{?id}')]
    public function onGet(string $id): static
    {
        // Both queries execute in parallel
        return $this;
    }
}
```

File Structure
--------------

[](#file-structure)

```
var/sql/query/
  user_profile.sql
  user_orders.sql

src/Projection/
  UserProfile.php
  UserProfileFactory.php
  UserOrders.php
  UserOrdersFactory.php

```

Naming Conventions
------------------

[](#naming-conventions)

SQL fileFactory classURI`user_profile.sql``UserProfileFactory``query://self/user_profile``user_orders.sql``UserOrdersFactory``query://self/user_orders`

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance78

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

113d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/db4fc75ffc631168d0d7143b6f2c24b1534dfb921212bd851c026c5cbbb1344d?d=identicon)[koriym](/maintainers/koriym)

---

Top Contributors

[![koriym](https://avatars.githubusercontent.com/u/529021?v=4)](https://github.com/koriym "koriym (22 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bear-projection/health.svg)

```
[![Health](https://phpackages.com/badges/bear-projection/health.svg)](https://phpackages.com/packages/bear-projection)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
