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

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

methorz/swift-db
================

High-performance MySQL database layer with bulk operations, PDO-based

v1.2.0(2mo ago)151MITPHPPHP ^8.3 || ^8.4CI passing

Since Dec 15Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/MethorZ/swift-db)[ Packagist](https://packagist.org/packages/methorz/swift-db)[ RSS](/packages/methorz-swift-db/feed)WikiDiscussions main Synced 1mo ago

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

MethorZ SwiftDb
===============

[](#methorz-swiftdb)

[![CI](https://github.com/methorz/swift-db/actions/workflows/ci.yml/badge.svg)](https://github.com/methorz/swift-db/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/543bb5cf3b30cfe89da2ad6d577399e3efd3fd3f27eeab4f532616fec1d9c68b/68747470733a2f2f636f6465636f762e696f2f67682f6d6574686f727a2f73776966742d64622f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/methorz/swift-db)[![PHPStan](https://camo.githubusercontent.com/3d63a7e6e05ca0dafbdd1cb2da881539a5ccd543deb25f6d8d1174cd11815bfe/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c2532306d61782d627269676874677265656e2e7376673f7374796c653d666c6174)](https://phpstan.org/)[![PHP Version](https://camo.githubusercontent.com/ef0054230522e542bc1f908ac005c6c75888dea255bac910f9015e12095e31d7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e332d626c7565)](https://www.php.net/)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

High-performance MySQL database layer with bulk operations, built on PDO.

Features
--------

[](#features)

- **High Performance**: Direct PDO with no abstraction overhead
- **Bulk Operations**: Multi-row INSERT, INSERT...ON DUPLICATE KEY UPDATE
- **Entity Pattern**: Clean entity classes with dirty tracking
- **Repository Pattern**: Type-safe repositories with query builder
- **MySQL Optimized**: Designed specifically for MySQL
- **Deadlock Handling**: Automatic retry with exponential backoff
- **Connection Management**: Master/slave support, reconnection handling
- **Query Logging**: Built-in debugging and monitoring

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

[](#installation)

```
composer require methorz/swift-db
```

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

[](#quick-start)

### Configuration

[](#configuration)

```
// config/autoload/database.global.php
return [
    'database' => [
        'connections' => [
            'default' => [
                'dsn' => 'mysql:host=localhost;dbname=myapp;charset=utf8mb4',
                'username' => 'root',
                'password' => '',
            ],
            'replica' => [
                'dsn' => 'mysql:host=replica;dbname=myapp;charset=utf8mb4',
                'username' => 'readonly',
                'password' => '',
            ],
        ],
        'default' => 'default',
        'read_from' => 'replica',  // Optional: route reads to replica
        'write_to' => 'default',   // Optional: route writes to master
        'cache_dir' => 'data/cache/database',  // Optional: for reflection cache
    ],
];
```

### Define an Entity

[](#define-an-entity)

```
