PHPackages                             switon/db - 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. switon/db

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

switon/db
=========

Direct SQL client with named binds, transient transactions, and optional read or write routing for Switon Framework

v1.0.0(1mo ago)084MITPHPPHP &gt;=8.3CI passing

Since Jun 6Pushed 1mo agoCompare

[ Source](https://github.com/switon-php/db)[ Packagist](https://packagist.org/packages/switon/db)[ Docs](https://github.com/switon-php/db)[ RSS](/packages/switon-db/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (8)Versions (2)Used By (4)

Switon DB Package
=================

[](#switon-db-package)

[![CI](https://camo.githubusercontent.com/649f060457a7510279803fcfe6084fd1cf54872ac97c22ec15713f590f83eed2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f737769746f6e2d7068702f64622f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d4349)](https://github.com/switon-php/db/actions/workflows/ci.yml) [![PHP 8.3+](https://camo.githubusercontent.com/c03f51341eebaefabbf137e291b20523fc74b4ffd084406d88524d266d95085d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d373737424234)](https://www.php.net/)

Switon's database client layer for direct table operations, routed reads, pooled connections, transaction-safe connections, and SQL observability.

Highlights
----------

[](#highlights)

- **Table operations:** `ClientInterface` offers `insert`, `update`, `upsert`, and `delete` alongside raw SQL.
- **Read/write routing:** reads and writes can be split across the right pool automatically.
- **Connection pooling:** read and write calls reuse pooled connections, with transient clients available for transactions.
- **Transient transaction clients:** local transactions can use a client pinned to one connection.
- **Metadata and SQL helpers:** table metadata and SQL builders are available from the same client.
- **Observable queries:** DB events can feed collectors such as `SqlCollector`.

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

[](#installation)

```
composer require switon/db
```

Quick Start
-----------

[](#quick-start)

```
use Switon\Core\Attribute\Autowired;
use Switon\Db\ClientInterface;

final class UserRepository
{
    #[Autowired] protected ClientInterface $db;

    public function find(int $id): ?array
    {
        $rows = $this->db->fetchAll(
            'SELECT * FROM [users] WHERE id = :id LIMIT 1',
            ['id' => $id],
        );

        return $rows[0] ?? null;
    }

    public function rename(int $id, string $name): void
    {
        $db = $this->db->getTransient('default');
        $db->begin();

        try {
            $db->executeUpdate(
                'UPDATE [users] SET name = :name WHERE id = :id',
                ['id' => $id, 'name' => $name],
            );
            $db->commit();
        } catch (\Throwable $e) {
            $db->rollback();
            throw $e;
        }
    }
}
```

Docs:

License
-------

[](#license)

MIT.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance90

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

48d ago

### Community

Maintainers

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

---

Top Contributors

[![switon-php](https://avatars.githubusercontent.com/u/247358032?v=4)](https://github.com/switon-php "switon-php (1 commits)")

---

Tags

databasedbpdosqlswitontransactionsdatabasesqlpdotransactionsswiton

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/switon-db/health.svg)

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

###  Alternatives

[doctrine/dbal

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

9.7k605.0M7.0k](/packages/doctrine-dbal)[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k6.0M79](/packages/ifsnop-mysqldump-php)[aura/sqlquery

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

4883.1M40](/packages/aura-sqlquery)[paragonie/easydb

Easy-to-use database abstraction

736283.6k24](/packages/paragonie-easydb)[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k23.2k](/packages/clouddueling-mysqldump-php)[ezsql/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

86749.2k](/packages/ezsql-ezsql)

PHPackages © 2026

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