PHPackages                             xtompie/dao - 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. xtompie/dao

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

xtompie/dao
===========

DAO - Data Access Object - wrapper over SQL

1.13.0(5mo ago)03.6k↓37.5%MITPHPPHP &gt;=8.0

Since Aug 28Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/xtompie/dao)[ Packagist](https://packagist.org/packages/xtompie/dao)[ RSS](/packages/xtompie-dao/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (20)Used By (0)

DAO
===

[](#dao)

DAO - Data Access Object - wrapper over SQL

```
/** @var Xtompie\Dao\Dao $dao */
$dao->insert('user', ['email' => 'john.doe@exmaple.com', 'created_at' => time()]);
$records = $dao->query(['select' => '*', 'from' => 'user', 'limit' => 10]);
```

- [DAO](#dao)
    - [Requiments](#requiments)
    - [Installation](#installation)
    - [Docs](#docs)
        - [Createing Dao instance](#createing-dao-instance)
        - [Read](#read)
        - [Read from one table](#read-from-one-table)
        - [Write](#write)
        - [Transaction](#transaction)
        - [Extends AQL](#extends-aql)

Requiments
----------

[](#requiments)

PHP &gt;= 8.0

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

[](#installation)

Using [composer](https://getcomposer.org/)

```
composer require xtompie/dao

```

Docs
----

[](#docs)

### Createing Dao instance

[](#createing-dao-instance)

```
use PDO;
use Xtompie\Aql\Aql;
use Xtompie\Aql\PostgreSQLPlatform;
use Xtompie\Dao\Dao;

$dao = new Dao(
    adapter: new PdoAdapter(pdo: new PDO('pgsql:host=localhost;dbname=test', 'postgres')),
    aql: new Aql(platform: new PostgreSQLPlatform()),
);
```

Available bulid-in adapters `Xtompie\Dao\Adapter`:

- `Xtompie\Dao\DoctrineAdapter`
- `Xtompie\Dao\PdoAdapter`

Uses [AQL](https://github.com/xtompie/aql) format to build sql queries.

### Read

[](#read)

```
class Dao
{
    public function query(array $query): array {}
    // returns all selected rows

    public function first(array $query): ?array {}
    // return first selected row or null

    public function val(array $query): mixed {}
    // return first field from first selected row or null

    public function any(array $query): bool {}
    // return true if there is any data for given query else false

    public function count(array $query): int {}
    // returns number of selected rows, by default uses `COUNT(*)`

    public function stream(array $query): Generator {}
    // yield records
}
```

### Read from one table

[](#read-from-one-table)

```
class Dao
{
    public function records(string $table, ?array $where, ?string $order = null, ?int $offset = null, ?int $limit = null): array {}
    // similiar to `query`

    public function record(string $table, ?array $where = null, ?string $order = null, ?int $offset = null): ?array {}
    // similar to `first`

    public function amount(string $table, ?array $where = null, ?string $group = null): int {}
    // similiar to `count`

    public function exists(string $table, array $where): bool {}
    // similiar to `any`

    public function streamRecords(string $table, ?array $where = null, ?string $order = null, ?int $offset = null, ?int $limit = null): Generator
    // yield records

}
```

### Write

[](#write)

```
class Dao
{
    public function command(array $command): int {}

    public function insert(string $table, array $values): int {}

    public function insertBulk(string $table, array $bluk): int {}

    public function update(string $table, array $set, array $where): int {}

    public function upsert(string $table, array $set, array $where): int {}

    public function delete(string $table, array $where): int {}
}
```

Each method returns the number of affected rows

### Transaction

[](#transaction)

```
class Dao
{
    public function transaction(callable $callback) {}
    // run callback in transaction
}
```

### Extends AQL

[](#extends-aql)

```
namespace App\Shared\Dao;

use Xtompie\Dao\Dao as BaseDao;

interface Paging
{
    public function limit(): int;
    public function offset(): int;
}

class Dao extends BaseDao
{
    public function aql(array $aql): array
    {
        if (isset($aql['paging'])) {
            $paging = $aql['paging'];
            unset($aql['paging']);
            if (!$paging instanceof Paging) {
                throw new \Exception();
            }
            $aql['offset'] => $paging->offset();
            $aql['limit'] => $paging->limit();
        }
        return parent::aql($aql);
    }
}
```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance73

Regular maintenance activity

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~67 days

Recently: every ~99 days

Total

19

Last Release

150d ago

Major Versions

0.3 → 1.0.02024-03-17

### Community

Maintainers

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

---

Top Contributors

[![xtompie](https://avatars.githubusercontent.com/u/69162230?v=4)](https://github.com/xtompie "xtompie (15 commits)")

---

Tags

datadatabasesql

### Embed Badge

![Health badge](/badges/xtompie-dao/health.svg)

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

###  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)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[catfan/medoo

The lightweight PHP database framework to accelerate development

4.9k1.5M194](/packages/catfan-medoo)[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k5.5M69](/packages/ifsnop-mysqldump-php)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4572.9M34](/packages/aura-sqlquery)[foolz/sphinxql-query-builder

A PHP query builder for SphinxQL and ManticoreQL with MySQLi and PDO drivers.

3232.2M32](/packages/foolz-sphinxql-query-builder)

PHPackages © 2026

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