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

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

mathsgod/light-db
=================

1.6.1(2mo ago)097[1 PRs](https://github.com/mathsgod/light-db/pulls)2MITPHPPHP &gt;=8.1CI passing

Since May 16Pushed 2mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (14)Versions (24)Used By (2)

[![GitHub](https://camo.githubusercontent.com/bafb88b2c7d52b0104ecfff0ec02c16e650f965d9433af6e1dbf2479072fa557/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d61746873676f642f6c696768742d6462)](https://github.com/mathsgod/light-db)[![PHP](https://camo.githubusercontent.com/7535257ca228724c93658bd52583d4e47a9bab02c356abf6e54c1d575f2151e6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c75652e737667)](https://www.php.net/)[![Tests](https://camo.githubusercontent.com/ba6ce779dcd9ca1d0483f79cd45c93cc89346fbd5a63f509d1ac752dd2092ed9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d373325323070617373696e672d627269676874677265656e2e737667)](https://github.com/mathsgod/light-db)

Light-DB
========

[](#light-db)

Light-DB is a lightweight PHP ORM/database access layer built on top of Laminas DB, designed for modern PHP 8.1+ applications. It provides an Eloquent-like Model operation experience with support for auto-mapping, dynamic queries, relationship queries, JSON field operations, and pagination features.

✨ Features
----------

[](#-features)

- 🚀 **Modern PHP**: Built on PHP 8.1+ features with type declarations and modern PHP syntax
- 🔗 **Multi-Database Support**: Based on Laminas DB, supports MySQL, PostgreSQL, SQLite, SQL Server and more
- 📦 **Eloquent-Style**: Familiar Active Record pattern with Eloquent-like API
- 🎯 **Smart Queries**: Support for complex conditional queries, sorting, grouping, and aggregation functions
- 📄 **Pagination Support**: Built-in Laminas Paginator integration for easy pagination
- 🔄 **JSON Fields**: Native support for JSON field operations with automatic serialization/deserialization
- 🔗 **Relationship Queries**: Support for inter-model relationship queries and dynamic property access
- 🧪 **Comprehensive Testing**: 73+ test cases ensuring code quality and stability
- ⚡ **High Performance**: Lazy loading and query optimization for excellent performance

📋 Requirements
--------------

[](#-requirements)

- PHP 8.1 or higher
- PDO extension
- Supported databases: MySQL, PostgreSQL, SQLite, SQL Server, etc.

🚀 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require mathsgod/light-db
```

⚙️ Configuration
----------------

[](#️-configuration)

Create a `.env` file in your project root:

```
DATABASE_DRIVER=pdo_mysql
DATABASE_HOSTNAME=localhost
DATABASE_PORT=3306
DATABASE_DATABASE=your_database
DATABASE_USERNAME=your_username
DATABASE_PASSWORD=your_password
DATABASE_CHARSET=utf8mb4
```

🎯 Basic Usage
-------------

[](#-basic-usage)

### Defining Models

[](#defining-models)

```
