PHPackages                             iescarro/lekoi-model - 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. [Framework](/categories/framework)
4. /
5. iescarro/lekoi-model

ActiveLibrary[Framework](/categories/framework)

iescarro/lekoi-model
====================

A lightweight ORM and database abstraction layer for the Lekoi PHP framework.

v0.1.0(8mo ago)014MITPHPPHP &gt;=8.1

Since Oct 12Pushed 8mo agoCompare

[ Source](https://github.com/iescarro/lekoi-model)[ Packagist](https://packagist.org/packages/iescarro/lekoi-model)[ Docs](https://github.com/iescarro/lekoi-model)[ RSS](/packages/iescarro-lekoi-model/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

🧩 lekoi-model
=============

[](#-lekoi-model)

[![Lekoi Framework Logo](art/logo.png)](art/logo.png)

A lightweight database abstraction / ORM-like model component for the Lekoi PHP framework.
Supports **MySQL (mysqli)** and **SQLite3** through a consistent interface, and provides a simple **DB facade** and base **Model** capabilities.

---

🚀 Features
----------

[](#-features)

- Simple CRUD operations: `insert()`, `update()`, `delete()`, `get()`, `result()`, `row()`
- Works with both MySQL (`mysqli`) and SQLite3 with one unified API
- DB facade (`DB::…`) for convenient static access
- Base `Model` class support (if you add it) for cleaner domain models
- Lightweight and minimal dependencies (just `php-util` currently)

---

📦 Installation
--------------

[](#-installation)

Via Composer:

```
composer require iescarro/lekoi-model
```

Then in your project’s composer.json, you’ll get Lekoi\\ namespace autoloaded pointing to the src/ directory.

📁 Directory Structure (Recommended)
-----------------------------------

[](#-directory-structure-recommended)

```
lekoi-model/
├── src/
│   ├── Database/
│   │   ├── MySQLDatabase.php
│   │   ├── SQLiteDatabase.php
│   │   └── IDatabase.php
│   ├── DB.php
│   └── Model.php
├── tests/
│   └── (unit tests)
├── .env.example
├── composer.json
└── README.md
```

🧰 Usage
-------

[](#-usage)

### 1. Configure DB Facade

[](#1-configure-db-facade)

Before using DB, initialize it with your connection settings (e.g. in your app’s bootstrap or index.php):

```
DB::init([
    'driver'   => 'mysqli',       // or 'sqlite3'
    'host'     => getenv('DB_HOST'),
    'port'     => getenv('DB_PORT'),
    'dbname'   => getenv('DB_DATABASE'),
    'username' => getenv('DB_USERNAME'),
    'password' => getenv('DB_PASSWORD'),
]);
```

For SQLite you might do:

```
DB::init([
    'driver' => 'sqlite3',
    'dbname' => __DIR__ . '/data/database.sqlite',
]);
```

### 2. CRUD Examples

[](#2-crud-examples)

```
// Insert
DB::insert('users', [
    'name' => 'Alice',
    'email' => 'alice@example.com',
]);

// Update
DB::update(
    'users',
    ['email' => 'alice.new@example.com'],
    ['id' => 1]
);

// Delete
DB::delete('users', [
    'id' => 1
]);

// Get rows
$rows = DB::get('users', ['status' => 'active'])->result();

foreach ($rows as $row) {
    echo $row['name'] . PHP_EOL;
}

// Get single row (if you define row())
$user = DB::get('users', ['id' => 2])->row();
```

🧬 (Optional) Model Extension
----------------------------

[](#-optional-model-extension)

You can build a base Model class to streamline usage in your domain classes:

```
class Model
{
    protected $table;
    protected $primaryKey = 'id';
    protected $attributes = [];

    public function __construct(array $attrs = [])
    {
        $this->attributes = $attrs;
    }

    public function save(): bool
    {
        if (isset($this->attributes[$this->primaryKey])) {
            return DB::update(
                $this->table,
                $this->attributes,
                [$this->primaryKey => $this->attributes[$this->primaryKey]]
            );
        } else {
            return DB::insert($this->table, $this->attributes);
        }
    }

    public static function find(int $id): ?self
    {
        $row = DB::get(static::$table, [static::$primaryKey => $id])->row();
        return $row ? new static($row) : null;
    }
}
```

Then your domain model:

```
class User extends Model
{
    protected $table = 'users';
    protected $primaryKey = 'id';
    // optionally define fillable or guarded etc.
}
```

Usage:

```
$user = User::find(1);
$user->name = 'Bob';
$user->save();

$users = DB::get('users')->result();
```

🧪 Testing
---------

[](#-testing)

You can add unit tests (e.g. using PHPUnit) under tests/ to ensure your DB and Database classes behave as expected across both drivers. Add the test dependency to composer.json under require-dev.

Run tests via:

```
composer test
```

⚙️ Configuration &amp; Best Practices
-------------------------------------

[](#️-configuration--best-practices)

- Validate table &amp; column names (e.g. alphanumeric + underscores) to avoid SQL injection risks.
- Use environment variables or a config file to keep credentials outside version control.
- Consider connection pooling or persistent connections for production use.
- Log queries (e.g. via a queryLog() method) to help debugging.
- Extend support for more drivers (PostgreSQL, SQL Server, etc.) by implementing new driver classes that adhere to IDatabase.

📜 License
---------

[](#-license)

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

💡 Contribution
--------------

[](#-contribution)

Contributions, issues, and feature requests are welcome! Please feel free to:

- Open a bug report or feature request
- Submit pull requests
- Add tests for new features or drivers

🧷 References &amp; Inspiration
------------------------------

[](#-references--inspiration)

- CodeIgniter 3’s Model / Database pattern
- Laravel’s Eloquent / DB facade design
- Doctrine / other ORMs as inspiration for future expansion

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance60

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

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

Every ~3 days

Total

4

Last Release

256d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/334216?v=4)[Ian](/maintainers/iescarro)[@iescarro](https://github.com/iescarro)

---

Top Contributors

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

---

Tags

phpframeworkdatabaseormsqlitemysqlilekoi

### Embed Badge

![Health badge](/badges/iescarro-lekoi-model/health.svg)

```
[![Health](https://phpackages.com/badges/iescarro-lekoi-model/health.svg)](https://phpackages.com/packages/iescarro-lekoi-model)
```

###  Alternatives

[opulence/opulence

The Opulence PHP framework

71929.0k2](/packages/opulence-opulence)[zemit-cms/core

Build Phalcon REST APIs faster with database-first scaffolding, model relationships, eager loading, identity, permissions, CLI, and WebSocket support.

148.5k1](/packages/zemit-cms-core)[mirekmarek/php-jet

PHP Jet is modern, powerful, real-life proven, really fast and secure, small and light-weight framework for PHP8 with great clean and flexible modular architecture containing awesome developing tools. No magic, just clean software engineering.

241.3k](/packages/mirekmarek-php-jet)

PHPackages © 2026

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