PHPackages                             kappa/deaw - 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. kappa/deaw

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

kappa/deaw
==========

Tiny wrapper for better and more comfortable works with Dibi

v1.0.0(9y ago)0316MITPHPPHP &gt;= 5.4.0

Since Jun 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/Kappa-org/Deaw)[ Packagist](https://packagist.org/packages/kappa/deaw)[ Docs](https://github.com/Kappa-org/Deaw)[ RSS](/packages/kappa-deaw/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (6)Versions (3)Used By (0)

Kappa\\Deaw
===========

[](#kappadeaw)

[![Build Status](https://camo.githubusercontent.com/2e4653e958a46aae69db662e7c98eff57630449c9526212a56c6d98fc1989132/68747470733a2f2f7472617669732d63692e6f72672f4b617070612d6f72672f446561772e737667)](https://travis-ci.org/Kappa-org/Deaw)

Tiny wrapper for better and more comfortable works with [dibi](http://dibiphp.com)

Content
-------

[](#content)

- [Requirements](#requirements)
- [Installation](#installation)
- [How to use](#how-to-use)
    - [Fetches](#fetches)
    - [Execute](#execute)
    - [Transactions](#transactions)
    - [Query objects](#query-objects)
- [Development](#development)
    - [Tests](#tests)

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

[](#requirements)

Full list of dependencies you can get from [Composer config file](https://github.com/Kappa-org/Deaw/blob/master/composer.json)

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

[](#installation)

The best way to install Kappa\\Deaw is using [Composer](https://getcomposer.org)

```
$ composer require kappa/deaw:@dev
```

Before your first usage you must have registered `dibi` with required settings.

```
extensions:
  dibi: Dibi\Bridges\Nette\DibiExtension22

dibi:
  host: 127.0.0.1
  username: root
  password:
  database: test
  driver: mysql
```

When you have `dibi` registered you can add `Kappa\Deaw` extension without any extra configuration (all configuration will be used from `dibi` package).

```
extensions:
   dibi: Dibi\Bridges\Nette\DibiExtension22
   - \Kappa\Deaw\DI\DeawExtension

 dibi:
   host: 127.0.0.1
   username: root
   password:
   database: test
   driver: mysql
```

How to use
----------

[](#how-to-use)

The basic principe of this package is combine [*domain queries*(cz)](https://www.rarous.net/weblog/377-domenove-dotazy.aspx)and *`dibi` way*. This package provides a query objects which can be used for fetching or executing queries and which is distributed into custom classes.

Usage this package is very easy. `Kappa\Deaw` provides one base class `Kappa\Deaw\DataAccess` for make works with `dibi` more comfortable. With this class you can make all fetches, executes and you can work with transactions.

Firstly, you can inject this class into your model

```
class Users {

    private $dataAccess;

    public function __construct(\Kappa\Deaw\DataAccess $dataAccess) {
        $this->dataAccess = $dataAccess;
    }
}
```

prepare the basic fetch query object which must implements `\Kappa\Deaw\Query\Queryable` interface or for easy query objects you can use abstract class `\Kappa\Deaw\Query\QueryObject`

```
class FetchAdminUsers extends QueryObject { // or implments Queryable
    public function doQuery(QueryBuilder $builder) {
        return $builder->createQuery()->select('*')
            ->from('user')
            ->where('role = ?', 'admin');
    }
}
```

and now we can combine into model

```
class Users {

    private $dataAccess;

    public function __construct(\Kappa\Deaw\DataAccess $dataAccess) {
        $this->dataAccess = $dataAccess;
    }

    public function getAdmins() {
        return $this->dataAccess->fetch(new FetchAdminUsers());
    }
}
```

and it's all!

### Fetches

[](#fetches)

The basic fetch principe is explained above. You can use three methods for fetching data.

- `fetch` - for fetch all records (alternative to `fetchAll` from `dibi`)
- `fetchOne` - for fetch only one record (alternative to `fetch` from `dibi`)
- `fetchSingle` - for fetch single value (alternative to `fetchSingle` from `dibi`)

### Execute

[](#execute)

You can also run executable query object for insert, update or remove data. For example:

```
class AddNewAdminUser extends QueryObject
{
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function doQuery(QueryBuilder $builder) {
        $builder->createQuery()->insert('users', [
            'name' => $this->name,
            'role' => 'admin'
        ]);
    }
}
```

and model

```
class Users {

    private $dataAccess;

    public function __construct(\Kappa\Deaw\DataAccess $dataAccess) {
        $this->dataAccess = $dataAccess;
    }

    public function addAdmin($name) {
        return $this->dataAccess->execute(new AddNewAdminUser($name));
    }
}
```

### Transactions

[](#transactions)

Also, you can use very easy transactions wrapper for typical `dibi` transactions.

We use `AddNewAdminUser` query object from previous example for example:

```
class Users {

    private $dataAccess;

    public function __construct(\Kappa\Deaw\DataAccess $dataAccess) {
        $this->dataAccess = $dataAccess;
    }

    public function addAdmins() {
        $transaction = $this->dataAccess->createTransaction();
        try {
            $this->dataAccess->execute(new AddNewAdminUser('foo'));
            $this->dataAccess->execute(new AddNewAdminUser('bar'));
            $transaction->commit();
        } catch (\Exception $e) {
            $transaction->rollback();
        }
    }
}
```

And of course you use savepoints (when is supported) as nested transactions

```
class Users {

    private $dataAccess;

    public function __construct(\Kappa\Deaw\DataAccess $dataAccess) {
        $this->dataAccess = $dataAccess;
    }

    public function addAdmins() {
        $transaction = $this->dataAccess->createTransaction();
        try {
            $this->dataAccess->execute(new AddNewAdminUser('foo'));
            $this->dataAccess->execute(new AddNewAdminUser('bar'));
            $nestedTransactions = $this->dataAccess->createTransaction();
            try {
                $this->dataAccess->execute(new AddNewAdminUser('foo_bar'));
                $nestedTransactions->commit(); // savepoint release is not required
            } catch (\Exception $e) {
                $nestedTransactions->rollback();
            }
            $transaction->commit();
        } catch (\Exception $e) {
            $transaction->rollback();
        }
    }
}
```

### Query objects

[](#query-objects)

The basic query object provide `postFetch` method which is called after each fetch. This method can be used for parsing data before return or for somethings else...

**TIP:** This method can be used for parsing to-many relations from string representation into array, for example:

SQL:

```
CREATE TABLE `articles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `title` varchar(255) COLLATE utf8_czech_ci NOT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  CONSTRAINT `articles_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;

INSERT INTO `articles` (`id`, `user_id`, `title`) VALUES
(1,	1,	'Foo_article_1'),
(2,	1,	'Foo_article_2'),
(3,	2,	'Bar_article_1'),
(4,	2,	'Bar_article_2');

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;

INSERT INTO `users` (`id`, `name`) VALUES
(1,	'Foo'),
(2,	'Bar');
```

```
class FetchToMany implements Queryable {
    public function doQuery(QueryBuilder $builder) {
        return $builder->createQuery()
            ->select('users.id, users.name, GROUP_CONCAT(articles.title SEPARATOR ',') as articles')
            ->leftJoin('articles')->on('articles.user_id = users.id')
            ->from('users');
    }

    public function postFetch($data) {
        foreach ($data as $key => $row) {
            $data[$key]['articles'] = explode(',', $data[$key]['articles'];
        }

        return $data;
    }
}
```

and results will be

```
    [
        [
            'id' => '1',
            'name' => 'Foo',
            'articles' => [
                'Foo_article_1',
                'Foo_article_2'
            ]
        ],
        [
            'id' => '2',
            'name' => 'Bar',
            'articles' => [
                'Bar_article_1',
                'Bar_article_2'
            ]
        ]
    ]
```

Development
-----------

[](#development)

### Tests

[](#tests)

When you can run test you must crate own config files. Please copy file `tests/config/config.sample.neon`, rename to `config.neon` (remove `sample`word) and update credentials in this file. Same do with `tests/config/database.sample.ini`

And now you can run test `./vendor/bin/tests -c ./tests/php-unix.ini ./tests`

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 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

Every ~204 days

Total

2

Last Release

3475d ago

Major Versions

v0.1.0 → v1.0.02016-12-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c0840abca14f130b93d02cfa8412e99dc0645ca3f7e57cf75cfcb487efe33aa?d=identicon)[Budry](/maintainers/Budry)

---

Top Contributors

[![Budry](https://avatars.githubusercontent.com/u/990676?v=4)](https://github.com/Budry "Budry (131 commits)")

---

Tags

wrapperdibibetter accesseasy access

### Embed Badge

![Health badge](/badges/kappa-deaw/health.svg)

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

###  Alternatives

[nette/bootstrap

🅱 Nette Bootstrap: the simple way to configure and bootstrap your Nette application.

68637.6M655](/packages/nette-bootstrap)[nette/caching

⏱ Nette Caching: library with easy-to-use API and many cache backends.

44119.3M403](/packages/nette-caching)[ssch/typo3-rector

Instant fixes for your TYPO3 PHP code by using Rector.

2603.2M436](/packages/ssch-typo3-rector)[ublaboo/datagrid

DataGrid for Nette Framework: filtering, sorting, pagination, tree view, table view, translator, etc

3042.0M26](/packages/ublaboo-datagrid)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136406.3k14](/packages/rector-rector-src)[brandembassy/slim-nette-extension

19201.2k](/packages/brandembassy-slim-nette-extension)

PHPackages © 2026

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