csitc/real-rap
Composer 安装命令:
composer require csitc/real-rap
包简介
Codeigniter ORM for 3.0 or higher
README 文档
README
This is a CI ORM, and inspired by laravel eloquent
中文地址: https://github.com/wugang8068/RealRap/blob/master/ReadMe_zh.md
How to install:
composer require csitc/real-rap dev-master
Retrieve
Example: We need to fetch the user where user_id >= 50 and order by user_id and user_mobile and get the first one
$users = User::all(['*'])->where([ 'user_id <=' => 50] )->order([ 'user_id' => 'desc', 'user_mobile' => 'desc']) ->limit(1)->getOne();
The result maybe like this:
{
"id":50,
"user_nick_name":"18386053521",
"user_device_id":"B86E62AC-5FC4-45E3-A3F0-EB4544DB135D",
"user_mobile":"17288",
"user_create_date":"2016-07-10 09:44:54"
}
In the User.php, we can just write like this:
class User extends Model{ protected $table = 'inf_user'; protected $primaryKey = 'user_id'; protected $cast = [ 'user_id' => 'integer', 'is_subscribed' => 'bool' ]; protected $hidden = [ 'agent_user', 'bank_real_name', 'is_subscribed', 'rebate_already_mentioned', 'rebate_being_mention', 'rebate_unmentioned', 'user_email' ]; protected $attributes = [ 'user_id' => 'id', ]; }
Update
$user = User::findWhere([ 'user_mobile' => '12381121695' ])->getOne(); if($user){ $user->user_mobile = '134234'; $user->save(); }
Create
$user = new User(); $user->user_nick_name = 'Tom'; $user->save();
Delete
$user = User::findWhere(['user_mobile' => '18600908262'])->getOne(); if($user){ print_r($user->delete() ? 'record delete success' : 'record delete failed'); }else{ print_r('record is not exists'); }
or
User::findWhere(['user_mobile' => '18600908262'])->delete()
Transaction
\RealRap\RealRap::trans(function(){ $user = new User(); $user->user_mobile = '13345727773'; $user->save(); $user = new User(); $user->user_mobile = '13347818106'; $user->save(); },function(){ echo 'success'; },function(){ echo 'error'; });
Model Relation
if we want to add model relation, for example, there is a table named ==inf_user==, and a table named ==inf_cd_keys==, and each recored in ==inf_user== has one or many record inf ==inf_cd_keys==, so it's easy to access the result with the flowing code;
First, get the user record
$this->user = User::all(['*'])->where([
'user_mobile' => '17010058640'
])->order([
'user_id' => 'desc',
'user_mobile' => 'desc'
])->limit(1)->getOne();
Then fetch if by the flowing:
$keys = $this->user->key
//The $keys is an array within objects or an object or null depends on the relation in User.php
The model can be write in this:
User.php
class User extends Model
{
protected $table = 'inf_user';
protected $primaryKey = 'user_id';
protected function key(){
return $this->hasMany(Key::class,'cdk_bind_user');
//return $this->hasOne(Key::class,'cdk_bind_user');
}
}
Key.php
class Key extends Model
{
protected $table = 'inf_cd_keys';
protected $primaryKey = 'cdk_id';
}
To DO LIST:
- Wrap the collection data instead of an array
csitc/real-rap 适用场景与选型建议
csitc/real-rap 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.87k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2016 年 09 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「orm」 「ci」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 csitc/real-rap 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 csitc/real-rap 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 csitc/real-rap 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
PeskyORM - annoying ORM that contains tons of exceptions and throws them when anything goes wrong
An ORM solution for Salesforce Object Query Language (SOQL)
LDAP ORM for Symfony2
Database layer for the Luany ecosystem — PDO connection, Model base, QueryBuilder, and Migration engine.
统计信息
- 总下载量: 5.87k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-09-23