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

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

neonus/db-layer
===============

A custom DBAL-based repository pattern.

v1.2.0(4mo ago)04proprietaryPHP

Since Dec 31Pushed 4mo agoCompare

[ Source](https://github.com/Neonus-sro/neonus-db-layer)[ Packagist](https://packagist.org/packages/neonus/db-layer)[ RSS](/packages/neonus-db-layer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

Neonus DB Layer
===============

[](#neonus-db-layer)

A lightweight PHP database abstraction layer built on top of **Doctrine DBAL** with a repository pattern implementation.

Overview
--------

[](#overview)

This package provides a clean, extensible database layer for PHP applications using:

- **Doctrine DBAL** for database interactions
- **Repository Pattern** for data access abstraction
- **Entity pattern** for object-oriented data representation
- **Factory pattern** for entity creation

Features
--------

[](#features)

- 🔧 **BaseRepository** - Abstract repository with common database operations
- 🏗️ **BaseEntity** - Abstract entity class with standard properties and methods
- 📦 **EntityFactory** - Factory for creating entity instances from data
- 🔌 **Extensible interfaces** - Easy to implement custom repositories and entities
- ✨ **Type-safe operations** - Parameter type handling for DBAL

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

[](#installation)

```
composer require neonus/db-layer
```

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

[](#requirements)

- PHP 7.4+
- Doctrine DBAL ^3.0 or ^4.0
- Symfony Dependency Injection ^8.0

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

[](#quick-start)

### 1. Create an Entity

[](#1-create-an-entity)

Extend `BaseEntity` to define your domain model:

```
namespace App\Entity;

use Neonus\DbLayer\Entity\BaseEntity;

class User extends BaseEntity
{
    protected string $name = '';
    protected string $email = '';
    protected string $url = '';

    public function getName(): string
    {
        return $this->name;
    }

    public function setName(string $name): void
    {
        $this->name = $name;
    }

    // Add more getters/setters...
}
```

### 2. Create a Repository

[](#2-create-a-repository)

Extend `BaseRepository` to implement data access logic:

```
namespace App\Repository;

use Neonus\DbLayer\Repository\BaseRepository;
use App\Entity\User;

class UserRepository extends BaseRepository
{
    public const TABLE_NAME = 'users';
    public const ENTITY_NAME = User::class;

    // Inherit basic CRUD operations, or add custom queries
}
```

### 3. Use the Repository

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

```
$userRepository = new UserRepository($connection, $entityFactory);

// Retrieve a user by ID
$user = $userRepository->get(1);

// Retrieve a user by URL
$user = $userRepository->getByUrl('john-doe');

// Create/Update a user
$user->setName('John Doe');
$userRepository->persist($user);

// Delete all records
$userRepository->deleteAll();
```

API Reference
-------------

[](#api-reference)

### BaseRepository

[](#baserepository)

#### Methods

[](#methods)

- **`get(int $id): BaseEntity|bool`** - Fetch a single entity by ID
- **`getByUrl(string $url): BaseEntity|bool`** - Fetch a single entity by URL
- **`persist(BaseEntity $entity, bool $forceInsert = false): int`** - Save or update an entity
- **`deleteAll(): int`** - Delete all records from the table
- **`getDb(): Connection`** - Access the DBAL connection directly

### BaseEntity

[](#baseentity)

#### Properties

[](#properties)

- **`id`** - Primary key (auto-managed)
- **`created_at`** - Creation timestamp (DateTime)

#### Methods

[](#methods-1)

- **`getId(): int`** - Get the entity ID
- **`setId(int $id): void`** - Set the entity ID
- **`getCreatedAt(): DateTime`** - Get creation timestamp
- **`setCreatedAt(mixed $created_at): void`** - Set creation timestamp
- **`toArray(): array`** - Convert entity to array

Project Structure
-----------------

[](#project-structure)

```
src/
├── Entity/
│   └── BaseEntity.php              # Base entity class
├── Repository/
│   └── BaseRepository.php          # Base repository class
├── Lib/
│   └── EntityFactory.php           # Entity factory
└── Interfaces/
    ├── RepositoryInterface.php     # Repository interface
    ├── HydratationInterface.php    # Hydration interface

```

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for a list of changes in each release.

License
-------

[](#license)

Proprietary - NEONUS, s.r.o.

Author
------

[](#author)

NEONUS, s.r.o. ()

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance77

Regular maintenance activity

Popularity3

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

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

Total

3

Last Release

127d ago

### Community

Maintainers

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

### Embed Badge

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

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

###  Alternatives

[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[bartlett/php-compatinfo-db

Reference Database of all functions, constants, classes, interfaces on PHP standard distribution and about 110 extensions

1183.0k1](/packages/bartlett-php-compatinfo-db)[edyan/neuralyzer

Library and CLI for Data anonymization

53147.1k2](/packages/edyan-neuralyzer)

PHPackages © 2026

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