PHPackages                             beauty-framework/database - 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. beauty-framework/database

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

beauty-framework/database
=========================

Beauty Database

1.0.0(11mo ago)0163MITPHPPHP &gt;=8.1

Since Jun 8Pushed 11mo agoCompare

[ Source](https://github.com/beauty-framework/database)[ Packagist](https://packagist.org/packages/beauty-framework/database)[ RSS](/packages/beauty-framework-database/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (3)

Beauty Database
===============

[](#beauty-database)

Lightweight, driver-based database module for the **Beauty Framework**. This package provides a flexible and extendable way to connect and interact with various relational databases through a `ConnectionInterface`, factory/strategy-based driver resolution, and a centralized `ConnectionRegistry`.

---

Features
--------

[](#features)

- PSR-compatible database access abstraction
- PDO-based drivers with automatic DSN resolution
- Out-of-the-box support for **SQLite**, **PostgreSQL**, **MySQL**, **SQL Server (sqlsrv)**
- Centralized connection registry with named connections
- Fully testable with in-memory SQLite
- Custom drivers support via strategy pattern
- Ability to fully replace PDO with any implementation via `ConnectionInterface`

---

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

[](#installation)

```
composer require beauty-framework/database
```

---

Usage
-----

[](#usage)

### 1. Define your database configuration

[](#1-define-your-database-configuration)

```
return [
    'default' => 'pgsql',

    'connections' => [
        'pgsql' => [
            'driver' => 'pgsql',
            'host' => '127.0.0.1',
            'port' => 5432,
            'database' => 'app',
            'username' => 'user',
            'password' => 'secret',
        ],

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => ':memory:',
        ],
    ],
];
```

### 2. Register connections in your container

[](#2-register-connections-in-your-container)

```
$factory = new ConnectionFactory([
    new PdoPgsqlDriver(),
    new PdoMysqlDriver(),
    new PdoSqliteDriver(),
    new PdoSqlsrvDriver(),
]);

$registry = new ConnectionRegistry($config['connections'], $factory, $config['default']);

$container->instance(ConnectionFactory::class, $factory);
$container->instance(ConnectionRegistry::class, $registry);
$container->instance(ConnectionInterface::class, $registry->get());
```

### 3. Use the connection

[](#3-use-the-connection)

```
/** @var ConnectionInterface $connection */
$connection = $container->get(ConnectionInterface::class);

$connection->execute("INSERT INTO users (name) VALUES (?)", ['Kirill']);
$users = $connection->query("SELECT * FROM users");
```

---

Supported Drivers
-----------------

[](#supported-drivers)

DriverPDO DriverNotes`pgsql``pgsql`PostgreSQL`mysql``mysql`MySQL / MariaDB`sqlite``sqlite`File-based or in-memory`sqlsrv``sqlsrv`SQL Server via Microsoft ext---

Writing a Custom Driver
-----------------------

[](#writing-a-custom-driver)

To register a new driver:

1. Implement `Beauty\Database\Connection\Drivers\DriverInterface`

```
class CustomDriver implements DriverInterface
{
    public function supports(string $driver): bool {
        return $driver === 'mydb';
    }

    public function make(array $config): ConnectionInterface {
        // return your own Connection implementation
    }
}
```

2. Register it into `ConnectionFactory`:

```
$factory = new ConnectionFactory([
    new MyCustomDriver(),
]);
```

---

Replacing PDO: Custom `ConnectionInterface`
-------------------------------------------

[](#replacing-pdo-custom-connectioninterface)

The `ConnectionInterface` only requires the following contract:

```
interface ConnectionInterface
{
    public function query(string $sql, array $bindings = []): mixed;
    public function select(string $sql, array $bindings = []): array;
    public function insert(string $sql, array $bindings = []): bool;
    public function update(string $sql, array $bindings = []): int;
    public function delete(string $sql, array $bindings = []): int;
    public function transaction(callable $callback): mixed;
    public function raw(string $sql): bool;
}
```

You can implement your own logic (e.g., HTTP-based DBs, gRPC, NoSQL emulation) by returning your own `ConnectionInterface` from a driver.

---

Testing
-------

[](#testing)

A full test suite is included using `PHPUnit`. Use SQLite in-memory for fast isolation:

```

```

```
$connection = $container->get(ConnectionInterface::class);
$connection->execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)");
```

---

License
-------

[](#license)

MIT

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance51

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity45

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

344d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/068f8c26f06f513a9c38d2a01c4d90a85eae1125a5b9d14eae7059715be860e4?d=identicon)[m1n64](/maintainers/m1n64)

---

Top Contributors

[![m1n64](https://avatars.githubusercontent.com/u/24874264?v=4)](https://github.com/m1n64 "m1n64 (1 commits)")

---

Tags

databasedbbeauty

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/beauty-framework-database/health.svg)

```
[![Health](https://phpackages.com/badges/beauty-framework-database/health.svg)](https://phpackages.com/packages/beauty-framework-database)
```

###  Alternatives

[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k46.2M405](/packages/robmorgan-phinx)[spatie/laravel-translation-loader

Store your language lines in the database, yaml or other sources

8362.9M51](/packages/spatie-laravel-translation-loader)[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)[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

925511.7k13](/packages/envms-fluentpdo)[lichtner/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921274.8k6](/packages/lichtner-fluentpdo)[fpdo/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921244.9k7](/packages/fpdo-fluentpdo)

PHPackages © 2026

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