ntentan / nzemba
A repository based ORM for ntentan.
dev-main
2026-09-25 09:29 UTC
Requires
- ntentan/kaikai: ^0.7.5
- ntentan/utils: ^0.13.2
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-25 09:31:55 UTC
README
A lightweight, repository-based ORM and data access library for the ntentan framework.
Features
- Repository Pattern: Clean separation of domain models and database persistence.
- Model Reflection & Caching: Automatic schema extraction and property caching using
ntentan/kaikai. - Driver-Agnostic Query Generation: Pluggable SQL query generation (e.g., PostgreSQL support via
PostgresQueryGenerator). - PDO Integration: Seamless integration with PDO for prepared statements and data mapping.
Requirements
- PHP 8.0+
ntentan/utilsntentan/kaikaipdoand relevant database drivers (e.g.,pdo_pgsql)
Installation
Install via Composer:
composer require ntentan/nzemba
Basic Usage
1. Define a Model
namespace App\Models; class User { public ?int $id = null; public string $name; public string $email; }
2. Configure and Instantiate Repository
use App\Models\User; use ntentan\nzemba\Repository; use ntentan\nzemba\generators\Postgres; $pdo = new PDO('pgsql:host=localhost;dbname=myapp', 'username', 'password'); $generator = new Postgres($pdo); // Repository resolves table name to pluralized decamelized form (e.g., 'users') $userRepository = new Repository(User::class, $generator); // Insert a record $userId = $userRepository->insert([ 'name' => 'Jane Doe', 'email' => 'jane@example.com' ]);
3. Service Container Configuration
You can also use Repository::getService() helper for dependency injection wiring:
$services = Repository::getService([ 'dsn' => 'pgsql:host=localhost;dbname=myapp', 'user' => 'username', 'password' => 'password' ]);
License
This project is licensed under the MIT License.