PHPackages                             dedsecteam17/soft-mapper - 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. dedsecteam17/soft-mapper

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

dedsecteam17/soft-mapper
========================

A lightweight, powerful, and easy-to-use PHP ORM library for MySQL databases with advanced features including relationships, soft deletes, and automatic timestamps

v2.0.0(6mo ago)10MITPHPPHP &gt;=5.6

Since Oct 28Pushed 6mo agoCompare

[ Source](https://github.com/DedSecTeam17/Soft-Mapper)[ Packagist](https://packagist.org/packages/dedsecteam17/soft-mapper)[ Docs](https://github.com/DedSecTeam17/Soft-Mapper)[ RSS](/packages/dedsecteam17-soft-mapper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (5)Used By (0)

Soft-Mapper
===========

[](#soft-mapper)

[![PHP Version](https://camo.githubusercontent.com/fb5884f1cf26bad55268f33a56c7291cc6fbd44034e5f57a0ae16a4836f8b4f8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344253230352e362d626c7565)](https://packagist.org/packages/dedsecteam17/soft-mapper)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)[![Status](https://camo.githubusercontent.com/d2656a901783e71666d7809f3464464fa4464d567a223f27ce4a2b747864f169/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374617475732d6163746976652d627269676874677265656e)](https://github.com/DedSecTeam17/Soft-Mapper)[![Version](https://camo.githubusercontent.com/32f0e853e1d0304b28815847f5541314691bfa6ee795cd57a846c8ad3a627c2b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d322e302e302d6f72616e6765)](https://github.com/DedSecTeam17/Soft-Mapper/releases)[![Packagist](https://camo.githubusercontent.com/87bad4686cc8a8f065bf2eea64c5a54064dc188e0544bee3bf25613b70b4e8e9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465647365637465616d31372f736f66742d6d61707065722e737667)](https://packagist.org/packages/dedsecteam17/soft-mapper)[![Packagist Downloads](https://camo.githubusercontent.com/b67d7c41d3537cb75a5afcbc172eec268c8b2a213422f46445230f777c5945e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6465647365637465616d31372f736f66742d6d61707065722e737667)](https://packagist.org/packages/dedsecteam17/soft-mapper)

A lightweight, powerful, and easy-to-use PHP ORM (Object-Relational Mapping) library for MySQL databases. Soft-Mapper provides a clean and intuitive interface for database operations with built-in security features and advanced ORM capabilities.

🚀 What's New in v2.0
--------------------

[](#-whats-new-in-v20)

Version 2.0 brings **27 new methods** and **advanced ORM features** that make Soft-Mapper comparable to Laravel's Eloquent:

- ✨ **Automatic Timestamps** - Auto-manage created\_at/updated\_at
- ✨ **Soft Deletes** - Mark records as deleted without removing them
- ✨ **ORM Relationships** - Define 1:1, 1:N, and N:N relationships (NEW!)
- ✨ **Eager Loading** - Load relationships efficiently to prevent N+1 queries (NEW!)
- ✨ **Query Scopes** - Reusable query constraints
- ✨ **Batch Operations** - Insert multiple records efficiently
- ✨ **Transactions** - Full transaction support
- ✨ **Advanced Queries** - whereIn, whereBetween, whereNull, JOINs
- ✨ **Helper Methods** - count(), exists(), first(), pluck()
- ✨ **And much more!** - See [CHANGELOG.md](CHANGELOG.md) for complete list

**📚 Documentation:**

- [Quick Start Guide](QUICK_START.md) - Get started with new features
- [ORM Relationships Guide](RELATIONSHIPS.md) - Complete guide to relationships (NEW!)
- [Changelog](CHANGELOG.md) - Complete list of changes
- [Advanced Examples](advanced-example.php) - Real-world usage examples

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Creating Models](#creating-models)
    - [Basic CRUD Operations](#basic-crud-operations)
    - [Advanced Queries](#advanced-queries)
    - [Aggregate Functions](#aggregate-functions)
- [Advanced Features](#advanced-features)
- [API Reference](#api-reference)
- [Examples](#examples)
- [Security](#security)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
- [License](#license)
- [Author](#author)

Features
--------

[](#features)

### Core Features

[](#core-features)

- ✅ **Simple and Intuitive API**: Easy-to-understand method chaining interface
- ✅ **Full CRUD Support**: Create, Read, Update, and Delete operations
- ✅ **Query Builder**: Build complex SQL queries with simple PHP methods
- ✅ **Security First**: Built-in prepared statements prevent SQL injection
- ✅ **Aggregate Functions**: Support for COUNT, SUM, AVG, MIN, MAX, etc.
- ✅ **Flexible Filtering**: WHERE and HAVING clauses with multiple conditions
- ✅ **Result Ordering**: ORDER BY with ASC/DESC support
- ✅ **Result Grouping**: GROUP BY for aggregate queries
- ✅ **Result Limiting**: LIMIT clause for pagination
- ✅ **Method Chaining**: Chain multiple methods for complex queries
- ✅ **PDO-Based**: Uses PHP Data Objects for database abstraction
- ✅ **Lightweight**: Minimal dependencies, single-file implementation

### Advanced Features ⭐ NEW

[](#advanced-features--new)

- ✨ **Automatic Timestamps**: Auto-manage created\_at and updated\_at columns
- ✨ **Soft Deletes**: Mark records as deleted without removing from database
- ✨ **ORM Relationships**: Define and query 1:1, 1:N, and N:N relationships
- ✨ **Eager Loading**: Load relationships efficiently with with()
- ✨ **Relationship Methods**: hasOne(), hasMany(), belongsTo(), belongsToMany()
- ✨ **Pivot Table Operations**: attach(), detach(), sync() for many-to-many
- ✨ **Pagination with OFFSET**: Full pagination support with limit and offset
- ✨ **Custom Primary Keys**: Support for non-'id' primary key columns
- ✨ **Batch Operations**: Insert multiple records efficiently with insertMany()
- ✨ **Query Scopes**: Define reusable query constraints
- ✨ **JOIN Support**: INNER JOIN, LEFT JOIN, RIGHT JOIN operations
- ✨ **Advanced WHERE Clauses**: whereIn, whereNotIn, whereBetween, whereNull
- ✨ **Helper Methods**: first(), count(), exists(), pluck()
- ✨ **Transaction Support**: Complete transaction management
- ✨ **Raw Queries**: Execute custom SQL when needed
- ✨ **Chunking**: Memory-efficient processing of large datasets
- ✨ **Update or Create**: Intelligent upsert operations
- ✨ **Distinct Results**: Get unique records only

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

[](#requirements)

- **PHP**: Version 5.6 or higher (PHP 7.x or 8.x recommended)
- **MySQL**: Version 5.5 or higher
- **PHP Extensions**:
    - PDO
    - PDO\_MySQL

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

[](#installation)

### Using Composer (Recommended)

[](#using-composer-recommended)

Install via Composer:

```
composer require dedsecteam17/soft-mapper
```

Then include the autoloader in your project:

```
require_once 'vendor/autoload.php';
```

### Manual Installation

[](#manual-installation)

1. Clone this repository or download the files:

```
git clone https://github.com/DedSecTeam17/Soft-Mapper.git
cd Soft-Mapper
```

2. Include the library in your project:

```
require_once 'path/to/SoftMapper.php';
```

### Using as a Git Submodule

[](#using-as-a-git-submodule)

```
git submodule add https://github.com/DedSecTeam17/Soft-Mapper.git libs/soft-mapper
```

Then include in your code:

```
require_once __DIR__ . '/libs/soft-mapper/SoftMapper.php';
```

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

[](#quick-start)

```
