PHPackages                             cakephp/datasource - 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. [Framework](/categories/framework)
4. /
5. cakephp/datasource

ActiveLibrary[Framework](/categories/framework)

cakephp/datasource
==================

Provides connection managing and traits for Entities and Queries that can be reused for different datastores

5.3.3(2mo ago)4724.6M—8.5%59MITPHPPHP &gt;=8.2

Since Nov 17Pushed today29 watchersCompare

[ Source](https://github.com/cakephp/datasource)[ Packagist](https://packagist.org/packages/cakephp/datasource)[ Docs](https://cakephp.org)[ RSS](/packages/cakephp-datasource/feed)WikiDiscussions 5.x Synced 1mo ago

READMEChangelogDependencies (10)Versions (339)Used By (9)

[![Total Downloads](https://camo.githubusercontent.com/dedd2f60d3fd05743332176df3e4ea0951d1add787dbfd806114771bad564c52/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63616b657068702f64617461736f757263652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cakephp/datasource)[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)

CakePHP Datasource Library
==========================

[](#cakephp-datasource-library)

This library contains interfaces for implementing Repositories and Entities using any data source, a class for managing connections to datasources and traits to help you quickly implement the interfaces provided by this package.

Repositories
------------

[](#repositories)

A repository is a class capable of interfacing with a data source using operations such as `find`, `save` and `delete` by using intermediate query objects for expressing commands to the data store and returning Entities as the single result unit of such a system.

In the case of a Relational database, a Repository would be a `Table`, which can be return single or multiple `Entity` objects by using a `Query`.

This library exposes the following interfaces for creating a system that implements the repository pattern and is compatible with the CakePHP framework:

- `RepositoryInterface` - Describes the methods for a base repository class.
- `EntityInterface` - Describes the methods for a single result object.
- `ResultSetInterface` - Represents the idea of a collection of Entities as a result of a query.

Additionally, this package provides a few traits and classes you can use in your own implementations:

- `EntityTrait` - Contains the default implementation for the `EntityInterface`.
- `QueryTrait` - Exposes the methods for creating a query object capable of returning decoratable collections.
- `ResultSetDecorator` - Decorates any traversable object, so it complies with `ResultSetInterface`.

Connections
-----------

[](#connections)

This library contains a couple of utility classes meant to create and manage connection objects. Connections are typically used in repositories for interfacing with the actual data source system.

The `ConnectionManager` class acts as a registry to access database connections your application has. It provides a place that other objects can get references to existing connections. Creating connections with the `ConnectionManager` is easy:

```
use Cake\Datasource\ConnectionManager;

ConnectionManager::config('connection-one', [
    'className' => 'MyApp\Connections\CustomConnection',
    'param1' => 'value',
    'param2' => 'another value'
]);

ConnectionManager::config('connection-two', [
    'className' => 'MyApp\Connections\CustomConnection',
    'param1' => 'different value',
    'param2' => 'another value'
]);
```

When requested, the `ConnectionManager` will instantiate `MyApp\Connections\CustomConnection` by passing `param1` and `param2` inside an array as the first argument of the constructor.

Once configured connections can be fetched using `ConnectionManager::get()`. This method will construct and load a connection if it has not been built before, or return the existing known connection:

```
use Cake\Datasource\ConnectionManager;
$conn = ConnectionManager::get('master');
```

It is also possible to store connection objects by passing the instance directly to the manager:

```
use Cake\Datasource\ConnectionManager;
$conn = ConnectionManager::config('other', $connectionInstance);
```

Documentation
-------------

[](#documentation)

Please make sure you check the [official API documentation](https://api.cakephp.org/4.x/namespace-Cake.Datasource.html)

###  Health Score

76

—

ExcellentBetter than 100% of packages

Maintenance94

Actively maintained with recent releases

Popularity60

Solid adoption and visibility

Community37

Small or concentrated contributor base

Maturity95

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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

Every ~12 days

Total

332

Last Release

65d ago

Major Versions

4.5.0-RC1 → 5.0.0-RC12023-06-01

4.5.0 → 5.0.22023-10-22

4.5.7 → 5.0.32023-11-21

4.6.2 → 5.1.42024-12-12

5.x-dev → 6.x-dev2026-03-15

PHP version history (7 changes)3.4.9PHP &gt;=5.6.0

4.0.0-beta1PHP &gt;=7.2.0

3.9.6PHP &gt;=5.6.0,&lt;8.0.0

4.4.0-RC1PHP &gt;=7.4.0

5.0.0-beta1PHP &gt;=8.1

5.3.0-RC1PHP &gt;=8.2

6.x-devPHP &gt;=8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/23666?v=4)[CakePHP](/maintainers/cakephp)[@cakephp](https://github.com/cakephp)

---

Top Contributors

[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (430 commits)")[![markstory](https://avatars.githubusercontent.com/u/24086?v=4)](https://github.com/markstory "markstory (379 commits)")[![dereuromark](https://avatars.githubusercontent.com/u/39854?v=4)](https://github.com/dereuromark "dereuromark (174 commits)")[![othercorey](https://avatars.githubusercontent.com/u/24221186?v=4)](https://github.com/othercorey "othercorey (133 commits)")[![lorenzo](https://avatars.githubusercontent.com/u/37621?v=4)](https://github.com/lorenzo "lorenzo (101 commits)")[![antograssiot](https://avatars.githubusercontent.com/u/4977112?v=4)](https://github.com/antograssiot "antograssiot (22 commits)")[![josegonzalez](https://avatars.githubusercontent.com/u/65675?v=4)](https://github.com/josegonzalez "josegonzalez (17 commits)")[![LordSimal](https://avatars.githubusercontent.com/u/9105243?v=4)](https://github.com/LordSimal "LordSimal (17 commits)")[![bcrowe](https://avatars.githubusercontent.com/u/752603?v=4)](https://github.com/bcrowe "bcrowe (17 commits)")[![robertpustulka](https://avatars.githubusercontent.com/u/7437773?v=4)](https://github.com/robertpustulka "robertpustulka (16 commits)")[![ravage84](https://avatars.githubusercontent.com/u/625761?v=4)](https://github.com/ravage84 "ravage84 (14 commits)")[![JoshuaLuckers](https://avatars.githubusercontent.com/u/1268085?v=4)](https://github.com/JoshuaLuckers "JoshuaLuckers (10 commits)")[![Harfusha](https://avatars.githubusercontent.com/u/47174548?v=4)](https://github.com/Harfusha "Harfusha (8 commits)")[![AD7six](https://avatars.githubusercontent.com/u/33387?v=4)](https://github.com/AD7six "AD7six (6 commits)")[![bar](https://avatars.githubusercontent.com/u/88155?v=4)](https://github.com/bar "bar (6 commits)")[![chinpei215](https://avatars.githubusercontent.com/u/7399393?v=4)](https://github.com/chinpei215 "chinpei215 (6 commits)")[![saeideng](https://avatars.githubusercontent.com/u/8215801?v=4)](https://github.com/saeideng "saeideng (5 commits)")[![dakota](https://avatars.githubusercontent.com/u/83255?v=4)](https://github.com/dakota "dakota (5 commits)")[![ndm2](https://avatars.githubusercontent.com/u/5031606?v=4)](https://github.com/ndm2 "ndm2 (5 commits)")[![Marlinc](https://avatars.githubusercontent.com/u/1240253?v=4)](https://github.com/Marlinc "Marlinc (4 commits)")

---

Tags

cakephpqueryentitydatasourceconnection management

### Embed Badge

![Health badge](/badges/cakephp-datasource/health.svg)

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

###  Alternatives

[composer/installers

A multi-framework Composer library installer

1.4k136.0M6.0k](/packages/composer-installers)[cakephp/cache

Easy to use Caching library with support for multiple caching backends

498.5M16](/packages/cakephp-cache)[cakephp/utility

CakePHP Utility classes such as Inflector, String, Hash, and Security

12127.1M63](/packages/cakephp-utility)[cakephp/database

Flexible and powerful Database abstraction library with a familiar PDO-like API

9824.6M33](/packages/cakephp-database)[cakephp/debug_kit

CakePHP Debug Kit

86514.0M138](/packages/cakephp-debug-kit)[cakephp/orm

CakePHP ORM - Provides a flexible and powerful ORM implementing a data-mapper pattern.

151242.6k70](/packages/cakephp-orm)

PHPackages © 2026

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