nemirovskiy/medoo-repository
Composer 安装命令:
composer require nemirovskiy/medoo-repository
包简介
Base repository implementation for Medoo with declarative table schema, strict field/type validation and simple schema installation.
关键字:
README 文档
README
Base repository implementation for Medoo that:
- Stores table schema (fields, types and options) in PHP arrays.
- Validates fields and types on create/update operations.
- Provides simple table installation (auto‑generated
CREATE TABLESQL from schema).
This library is useful when you want a lightweight, type‑checked repository layer on top of Medoo, without a full ORM.
Installation
Install via Composer:
composer require nemirovskiy/medoo-repository
Or, when developing locally, add the repository to your composer.json and require it.
Basic usage
1. Configure Medoo
use Medoo\Medoo; $database = new Medoo([ 'type' => 'mysql', 'host' => '127.0.0.1', 'database' => 'test', 'username' => 'root', 'password' => '', 'charset' => 'utf8mb4', ]);
2. Extend BaseRepository
namespace App\Repository; use Medoo\Medoo; use Medoo\Repository\BaseRepository; final class UserRepository extends BaseRepository { public function __construct(Medoo $db) { parent::__construct($db); $this->table = 'users'; $this->schema = [ 'id' => [ 'type' => 'int', 'unsigned' => true, 'auto_increment' => true, ], 'email' => [ 'type' => 'string', 'length' => 255, 'nullable' => false, 'unique' => true, ], 'name' => [ 'type' => 'string', 'length' => 255, 'nullable' => false, ], 'age' => [ 'type' => 'int', 'unsigned' => true, 'nullable' => true, ], 'active' => [ 'type' => 'bool', 'nullable' => false, 'default' => 1, ], 'created_at' => [ 'type' => 'datetime', 'nullable' => false, 'default' => 'CURRENT_TIMESTAMP', ], ]; $this->fillable = ['email', 'name', 'age', 'active']; $this->required = ['email', 'name']; } }
3. Install table and use the repository
use App\Repository\UserRepository; $users = new UserRepository($database); // Create table if it does not exist $users->install(); // Create user (fields and types are validated) $id = $users->create([ 'email' => 'john.doe@example.com', 'name' => 'John Doe', 'age' => 30, ]); // Load user $user = $users->findById($id); // Update user $users->update($id, [ 'age' => 31, 'active' => false, ]); // Delete user // $users->delete($id);
Key features
-
Declarative schema
Define your table columns in a PHP array: type, length, nullable, default, unique, indexes,auto_increment, etc. -
Strict validation
Oncreateandupdate:- Only
fillablefields are accepted. - Required fields must be present.
- Types are strictly validated (
int,float,bool,string,datetime). - Values outside schema cause an exception.
- Only
-
Schema installation (MySQL only)
install()builds aCREATE TABLE IF NOT EXISTSSQL statement based on schema and executes it via Medoo.
Only for MySQL/MariaDB. For PostgreSQL, SQLite or other databases, do not callinstall()/uninstall()— create and drop tables via your own migrations or overridegenerateCreateTableSql().
Database support
- CRUD (
create,findById,update,delete) works with any database Medoo supports (MySQL, PostgreSQL, SQLite, etc.). - install() and uninstall() generate and run MySQL-only SQL. Use them only with MySQL/MariaDB; for other DBs use migrations or override the schema methods.
Examples
There are runnable examples in the examples/ directory:
examples/UserRepository.php– demo user repositoryexamples/demo.php– demo script that installs the table and performs basic CRUD
Run:
php examples/demo.php
Make sure your database configuration in demo.php matches your local environment.
nemirovskiy/medoo-repository 适用场景与选型建议
nemirovskiy/medoo-repository 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「orm」 「php」 「repository」 「medoo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nemirovskiy/medoo-repository 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nemirovskiy/medoo-repository 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nemirovskiy/medoo-repository 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Kinikit - PHP Application development framework MVC component
Store your language lines in the database, yaml or other sources
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-11