定制 danielefavi/slim-orm 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

danielefavi/slim-orm

Composer 安装命令:

composer require danielefavi/slim-orm

包简介

Lightweight ORM with an API interface similar to Laravel's ORM Eloquent.

README 文档

README

Slim ORM is a lightweight PHP ORM with an API interface similar to the Laravel's ORM (Eloquent).

Please note this ORM has very basic query functionalities; for example it does not support relationships (like belongsToMany or belogsTo).
Please check some examples below.

Installation

Installation via composer

composer require danielefavi/slim-orm

Setup

Setting up the DB object with MySQL:

   $config = [
       'connection' => 'mysql',
       'name' => 'database-name',
       'username' => 'root',
       'password' => 'your_password',
       'options' => [
           \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
       ],
   ];

   $pdo = new \PDO(
       'mysql:host=' . $config['connection'] . ';dbname=' . $config['name'],
       $config['username'],
       $config['password'],
       $config['options']
   );

   $db = DB::init($pdo);

Setting up the DB object with SQLite:

   $pdo = new \PDO('sqlite:' . __DIR__ . '/sqlite.db');
   
   $db = DB::init($pdo);

Usage

Query Examples

Simple query example

$res = DB::table('users')
   ->where('name', 'Piripoppi')
   ->orWhere('age', '>=', 30)
   ->get();

Pagination

Return the paginated result (10 items per page).

$res = DB::table('users')
   ->orWhere('age', '>=', 30)
   ->paginate(10);

Full Query example

$res = DB::table('users')
   ->join('comments', '`users`.`id`', '=', '`comments`.`user_id`');
   ->where('id', '>', 30)
   ->where('id', '<=', 44)
   ->where(function($query) {
      $query->where('age', '>=', 10)
         ->orWhere('age', '<=', 20);
   })
   ->where(function($query) {
      $query->whereNull('age')
         ->orWhere('age', 20000);
   })
   ->orderByAsc('id')
   ->orderByDesc('file')
   ->orderBy('file', 'asc', 'field1', 'field2', 'desc', 'field3')
   ->limit(5)
   ->offset(3)
   ->groupBy('file', 'id')
   ->get();

Model

Defining a model

The model class must:

  • Extend the class DfTools\SlimOrm\Model.
  • Specify the database table the model represents, in the protected attribute $table.
  • Specify the primary key of the the database table of the model.
use DfTools\SlimOrm\Model;

class UserModel extends Model
{
    protected $table = 'users';

    protected $primaryKey = 'id';
}

Extra

Unittest

./vendor/bin/phpunit

For more examples please check the examples folder.

danielefavi/slim-orm 适用场景与选型建议

danielefavi/slim-orm 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 75 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 05 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 danielefavi/slim-orm 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 danielefavi/slim-orm 我们能提供哪些服务?
定制开发 / 二次开发

基于 danielefavi/slim-orm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 75
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-15