PHPackages                             ntentan/nibii - 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. ntentan/nibii

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

ntentan/nibii
=============

ORM for ntentan

v0.11.7(2w ago)02.2k↓78.5%[1 issues](https://github.com/ntentan/nibii/issues)[1 PRs](https://github.com/ntentan/nibii/pulls)1MITPHPCI failing

Since Nov 15Pushed 2w ago3 watchersCompare

[ Source](https://github.com/ntentan/nibii)[ Packagist](https://packagist.org/packages/ntentan/nibii)[ RSS](/packages/ntentan-nibii/feed)WikiDiscussions main Synced yesterday

READMEChangelog (2)Dependencies (12)Versions (35)Used By (1)

Nibii ORM
=========

[](#nibii-orm)

`ntentan/nibii` is a lightweight, intuitive, and powerful Active Record-based Object-Relational Mapper (ORM) for PHP. Built as the default database interface for the `ntentan` framework, it can also be configured and utilized as a standalone ORM library in any PHP project.

---

Features
--------

[](#features)

- **Active Record Pattern**: Represent database tables as PHP classes extending `RecordWrapper` for seamless interaction.
- **Dynamic Finders and Filters**: Query the database using expressive dynamic method calls like `filterByFieldName()` and `fetchFirstByFieldName()`.
- **Relationship Mapping**: Easy-to-use relationship configurations:
    - `BelongsTo`
    - `HasMany`
    - `ManyHaveMany` (with automatic pivot table handling)
- **Built-in Validation**: Easily validate model fields before saving, with support for field presence, types, and unique constraints.
- **Bulk Operations**: Perform batch inserts, updates, and deletes cleanly.

---

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

[](#installation)

Install `nibii` via [Composer](https://getcomposer.org/):

```
composer require ntentan/nibii
```

---

Initialization &amp; Configuration
----------------------------------

[](#initialization--configuration)

Before querying your models, initialize `DbContext` and `ORMContext`:

```
use ntentan\atiaa\DbContext;
use ntentan\atiaa\DriverFactory;
use ntentan\kaikai\Cache;
use ntentan\kaikai\backends\VolatileCache; // or any PSR-16 cache implementation
use ntentan\nibii\factories\DefaultModelFactory;
use ntentan\nibii\factories\DriverAdapterFactory;
use ntentan\nibii\factories\DefaultValidatorFactory;
use ntentan\nibii\ORMContext;

// Database connection details
$config = [
    'driver'   => 'postgresql', // e.g., 'postgresql', 'mysql', 'sqlite'
    'host'     => 'localhost',
    'user'     => 'db_user',
    'password' => 'db_password',
    'dbname'   => 'my_database',
];

// Initialize database contexts
DbContext::initialize(new DriverFactory($config));

ORMContext::initialize(
    new DefaultModelFactory(),
    new DriverAdapterFactory($config['driver']),
    new DefaultValidatorFactory(),
    new Cache(new VolatileCache())
);
```

---

Defining Models
---------------

[](#defining-models)

Models in `nibii` extend `ntentan\nibii\RecordWrapper`. By default, Nibii maps the model class name to a database table (e.g., a `Users` model maps to the `users` table).

```
namespace App\Models;

use ntentan\nibii\RecordWrapper;

class Users extends RecordWrapper
{
    // Define a belongsTo relationship to the Roles model
    protected $belongsTo = ['\App\Models\Roles'];
}
```

---

Usage Guide
-----------

[](#usage-guide)

### Fetching Records

[](#fetching-records)

`nibii` offers several convenient ways to retrieve data.

#### Fetching All Records

[](#fetching-all-records)

```
$users = (new Users())->fetch();
foreach ($users as $user) {
    echo $user->username;
}
```

#### Filtering Records

[](#filtering-records)

You can write custom filters using standard placeholders (`?` or named parameters):

```
// Using question mark placeholders
$user = (new Users())->filter('username = ?', 'james')->fetchFirst();

// Using named parameters
$user = (new Users())->filter('username = :username', [':username' => 'james'])->fetchFirst();
```

#### Dynamic Finders

[](#dynamic-finders)

Retrieve records using dynamic finder helper methods automatically generated from your column names:

```
// Find all users with role_id = 11 or 12
$users = (new Users())->filterByRoleId(11, 12)->fetch();

// Fetch first user matching a username
$user = (new Users())->fetchFirstWithUsername('james');
```

---

### Saving and Updating Records

[](#saving-and-updating-records)

#### Creating New Records

[](#creating-new-records)

Instantiate your model class, assign values as properties or array keys, and call `save()`:

```
$role = new Roles();
$role->name = 'Administrator';
// Or: $role['name'] = 'Administrator';

if ($role->save()) {
    echo "Saved successfully! ID: " . $role->id;
} else {
    // Validation failed
    print_r($role->getInvalidFields());
}
```

#### Updating Existing Records

[](#updating-existing-records)

```
$user = (new Users())->fetchFirstWithId(1);
if ($user) {
    $user->username = 'new_username';
    $user->save();
}
```

#### Bulk Updates

[](#bulk-updates)

You can update multiple records that match specific conditions in a single query:

```
// Update role_id to 15 for users matching role_id 11 or 12
(new Users())->filterByRoleId(11, 12)->update(['role_id' => 15]);
```

---

### Deleting Records

[](#deleting-records)

You can delete a set of records directly matching a query:

```
// Delete all users with ID less than 3
(new Users())->filter('id < ?', 3)->delete();
```

---

### Working with Relationships

[](#working-with-relationships)

Configure relationships directly in your class definition properties: `$belongsTo`, `$hasMany`, and `$manyHaveMany`.

#### BelongsTo Relationship

[](#belongsto-relationship)

```
class Users extends RecordWrapper
{
    protected $belongsTo = ['\App\Models\Roles'];
}
```

#### HasMany Relationship

[](#hasmany-relationship)

```
class Roles extends RecordWrapper
{
    protected $hasMany = ['\App\Models\Users'];
}
```

#### ManyHaveMany Relationship

[](#manyhavemany-relationship)

```
class Projects extends RecordWrapper
{
    public $manyHaveMany = ['\App\Models\Users'];
}
```

---

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file (if present) or `composer.json` for details.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance97

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 99.7% 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

Every ~154 days

Recently: every ~71 days

Total

26

Last Release

14d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f1786d9e3b51cbf4cb91ad00a4d4e02cd284f5485c850d34dca9debcd893390?d=identicon)[ekowabaka](/maintainers/ekowabaka)

---

Top Contributors

[![ekowabaka](https://avatars.githubusercontent.com/u/142054?v=4)](https://github.com/ekowabaka "ekowabaka (298 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ntentan-nibii/health.svg)

```
[![Health](https://phpackages.com/badges/ntentan-nibii/health.svg)](https://phpackages.com/packages/ntentan-nibii)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[ntentan/atiaa

A slim wrapper around PDO to provide some extra utilities

126.3k6](/packages/ntentan-atiaa)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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