myth/db
Composer 安装命令:
composer require myth/db
包简介
An effortless database abstraction built on top of CodeIgniter 4.
README 文档
README
Myth:db is an exploration of a possible new database layer for CodeIgniter 4. It adds a reflective Data Mapper to make getting data as simple as possible. While it uses Models and Entities in the background, it can be used with almost zero setup or code generation.
Examples
Getting all results in a table
The basic usage is with the map() method, which takes the name of the table you want to work with. It then creates a generic model, assigns the table name, inspects the table to populate the model's properties, and returns the model. Since you have a model, you then have access to the model methods, such as findAll(), and the Query Builder methods, such as where().
$users = db()->map('users')->findAll();
By default, this would return an array of objects, one for each of the rows in the table. If you would like to change the return type, you can pass in the name of the class, array, or object with the returns() method.
$users = db()->map('users')->returns('array')->findAll(); $users = db()->map('users')->returns(\App\Entities\User::class)->findAll();
Custom Entities
You can create your own Entities and the mapper will automatically return results in that format. This is all based on conventions. By default, it would look for an entity named User in the App\Entities namespace. The name of the Entity is the singular, PascalCase version of the table name.
// If App\Entities\User exists, all results will be returned as User objects // otherwise, each record will be returned as an object. $users = db()->map('users')->findAll(); // Would return each result as instance of App\Entities\ZodiacSign, if it exists. $signs = db()->map('zodiac_signs')->findAll();
Custom Models
You can also create your own Models and the mapper will automatically use that instead of the default Model. This is also based on conventions. It would look for a model named the PascalCase singular version of the table name, with Model appended to it.
// Will look for App\Models\UserModel $users = db()->map('users')->findAll(); // Will look for App\Models\ZodiacSignModel $signs = db()->map('zodiac_signs')->findAll();
NOTE: Returns an iterable cursor for better memory?
TODO: Return findX results as a collection?
myth/db 适用场景与选型建议
myth/db 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「codeigniter」 「codeigniter4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 myth/db 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 myth/db 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 myth/db 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
The CodeIgniter Redis package
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
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-30