PHPackages                             birkanoruc/simple-orm - 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. birkanoruc/simple-orm

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

birkanoruc/simple-orm
=====================

A lightweight ORM and database management library.

v1.0.0(1y ago)06MITPHPPHP &gt;=7.4

Since Oct 9Pushed 1y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (0)

Simple ORM
==========

[](#simple-orm)

**Simple ORM** is a lightweight Object-Relational Mapping library for PHP, designed to simplify database interactions and provide a clean and intuitive API for working with database records.

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

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Creating a Database Connection](#creating-a-database-connection)
    - [Creating a Model](#creating-a-model)
    - [Querying Data](#querying-data)
    - [Inserting Data](#inserting-data)
    - [Updating Data](#updating-data)
    - [Deleting Data](#deleting-data)
    - [Relationships](#relationships)
    - [Aggregates](#aggregates)
- [License](#license)

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

[](#installation)

To get started with Simple ORM, you can clone the repository or require it via Composer:

```
composer require birkanoruc/simple-orm
```

### Configuration

[](#configuration)

You need to configure your database connection settings. The following parameters are required:

- **host**: Database server address (e.g., `localhost`)
- **port**: Your DB port (e.g., `3306`)
- **dbname**: Database name
- **charset**: Character set (default is `utf8mb4`)

```
$config = [
'host' => '127.0.0.1',
'port' => 'your_db_port',
'dbname' => 'your_database',
'charset' => 'utf8mb4',
];
```

### Usage

[](#usage)

Creating a Database Connection

To create a new database connection, instantiate the Database class with your configuration:

```
use Birkanoruc\SimpleOrm\Database;

$config = [
    'host' => '127.0.0.1',
    'port' => 'your_db_port',
    'dbname' => 'your_database',
    'charset' => 'utf8mb4',
];

$db = new Database($config);
```

### Creating a Model

[](#creating-a-model)

Create a model by extending the Model class. Define the table name in the model:

```
namespace App\Models;

use Birkanoruc\SimpleOrm\Model;

class User extends Model
{
    protected $table = 'users';
}
```

### Querying Data

[](#querying-data)

To retrieve all records:

```
$userModel = new User($db);
$users = $userModel->all();
```

To retrieve the first record:

```
$user = $userModel->first();
```

To find a specific record by ID:

```
$user = $userModel->find(1);
```

To apply a WHERE clause:

```
$activeUsers = $userModel->where('active', '=', 1)->all();
```

### Inserting Data

[](#inserting-data)

To insert a new record:

```
$newUser = [
    'name' => 'John Doe',
    'email' => 'john@example.com',
];

$userModel->create($newUser);
```

### Updating Data

[](#updating-data)

To update an existing record:

```
$userModel->update(1, [
    'name' => 'John Smith',
]);
```

### Deleting Data

[](#deleting-data)

To delete a record:

```
$userModel->delete(1);
```

To delete multiple records:

```
$userModel->destroy([1, 2, 3]);
```

### Relationships

[](#relationships)

Define relationships within your model:

**Has One**

```
public function profile()
{
    return $this->hasOne(Profile::class);
}
```

**Has Many**

```
public function posts()
{
    return $this->hasMany(Post::class);
}
```

**Belongs To**

```
public function user()
{
    return $this->belongsTo(User::class);
}
```

**Belongs To Many**

```
public function roles()
{
    return $this->belongsToMany(Role::class, 'user_roles');
}
```

### Aggregates

[](#aggregates)

To perform aggregate queries:

```
$count = $userModel->count();
$sum = $userModel->sum('age');
$avg = $userModel->avg('salary');
$min = $userModel->min('age');
$max = $userModel->max('age');
```

### License

[](#license)

This project is licensed under the MIT License - see the LICENSE file for details.

### Explanations:

[](#explanations)

- **Project Introduction**: Clearly states the purpose of the library and what it does.
- **Installation**: Provides information on how to install and configure the library.
- **Usage**: Contains examples of how to use the library.
- **Relationships**: Offers information on how to define model relationships.
- **Aggregates**: Explains how to perform aggregate queries.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

586d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/94e74311ba8f7711c315a944e437092bbd422636396c05b056d526e776ca111f?d=identicon)[birkanoruc](/maintainers/birkanoruc)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/birkanoruc-simple-orm/health.svg)

```
[![Health](https://phpackages.com/badges/birkanoruc-simple-orm/health.svg)](https://phpackages.com/packages/birkanoruc-simple-orm)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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