PHPackages                             ray/cake-database-module - 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. ray/cake-database-module

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

ray/cake-database-module
========================

cakephp/database module for Ray.Di

1.0.1(8y ago)44822BSD-3-ClausePHPPHP &gt;=5.6.0

Since Mar 30Pushed 8y ago6 watchersCompare

[ Source](https://github.com/ray-di/Ray.CakeDbModule)[ Packagist](https://packagist.org/packages/ray/cake-database-module)[ RSS](/packages/ray-cake-database-module/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

Ray.CakeDbModule
================

[](#raycakedbmodule)

This is the [CakePHP Database](https://github.com/cakephp/database) Module for [Ray.Di](https://github.com/koriym/Ray.Di)

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

[](#installation)

### Composer install

[](#composer-install)

```
$ composer require ray/cake-database-module
```

### Module install

[](#module-install)

You can Inject the database Connection instance to any class this way:

```
use Ray\Di\AbstractModule;
use Ray\CakeDbModule\CakeDbModule;

class AppModule extends AbstractModule
{
    protected function configure()
    {
        $this->install(new CakeDbModule('sqlite:///'));

        // or
        $this->install(new CakeDbModule('mysql://root@localhost/cake_db'));
    }
}
```

That will create inject instances of `Cake\Database\Connection` with the SQLite driver using the memory database or connect to the localhost mysql using the root credentials.

You can also be more specific and pass a configuraiton array as `Cake\Database\Connection` would accept it:

```
use Ray\Di\AbstractModule;
use Ray\CakeDbModule\CakeDbModule;

class AppModule extends AbstractModule
{
    protected function configure()
    {
        $config = [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'username' => 'root',
            'password' => 'root',
            'database' => 'cake'
        ];
        $this->install(new CakeDbModule($config));
    }
}
```

Finally you can rely on already configured connections in cake's `ConnectionManager` and inject connections by name:

```
ConnectionManager::config('default', $config);
```

```
use Ray\Di\AbstractModule;
use Ray\CakeDbModule\CakeDbModule;

class AppModule extends AbstractModule
{
    protected function configure()
    {
        $this->install(new CakeDbModule('default'));
    }
}
```

### DI trait

[](#di-trait)

You can inject the connection instance on any class by using the `Ray\CakeDbModule\DatabaseInject` trait:

```
use Ray\CakeDbModule\DatabaseInject;

class MyThing
{
    use DatabaseInject;
}
```

This will make the methods `getDbConnection()` and `setDbConnection()` available in your class and will automatically inject the Connection instance when `MyThing` is instantiated using the Injector.

### Wrapping methods inside a transaction

[](#wrapping-methods-inside-a-transaction)

You can make any method run inside a transaction by using the `@Transactional` annotation. This is handy for saving operations:

```
use DateTime;
use Ray\CakeDbModule\Annotation\Trasactional;
use Ray\CakeDbModule\DatabaseInject;

class MyThing
{
    use DatabaseInject;

    /**
     * This will run inside a new transaction
     *
     * @Transactional
     */
    public function storeSomething()
    {
        $this->db->insert(
            'posts',
            ['name' => 'First', 'show_on' => new DateTime('+3 days')],
            ['created' => 'datetime']
        );
    }
}
```

### Demo

[](#demo)

```
$ php docs/demo/run.php
// It works!

```

### Requirements

[](#requirements)

- PHP 5.4+
- hhvm

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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

Every ~562 days

Total

3

Last Release

2944d ago

Major Versions

0.1.0 → 1.0.02015-05-04

### 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 (8 commits)")[![lorenzo](https://avatars.githubusercontent.com/u/37621?v=4)](https://github.com/lorenzo "lorenzo (7 commits)")[![antograssiot](https://avatars.githubusercontent.com/u/4977112?v=4)](https://github.com/antograssiot "antograssiot (1 commits)")

---

Tags

cakephp-databaseray-moduledbalcakephpRay.Di module

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ray-cake-database-module/health.svg)

```
[![Health](https://phpackages.com/badges/ray-cake-database-module/health.svg)](https://phpackages.com/packages/ray-cake-database-module)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[doctrine/doctrine-bundle

Symfony DoctrineBundle

4.8k241.3M3.3k](/packages/doctrine-doctrine-bundle)[doctrine/migrations

PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.

4.8k204.8M440](/packages/doctrine-migrations)[doctrine/doctrine-migrations-bundle

Symfony DoctrineMigrationsBundle

4.3k177.9M537](/packages/doctrine-doctrine-migrations-bundle)[fresh/doctrine-enum-bundle

Provides support of ENUM type for Doctrine2 in Symfony applications.

4636.8M12](/packages/fresh-doctrine-enum-bundle)[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)

PHPackages © 2026

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