承接 molovo/interrogate 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

molovo/interrogate

Composer 安装命令:

composer require molovo/interrogate

包简介

README 文档

README

Interrogate is a lightweight, standalone Object Relational Mapping (ORM) for PHP 5.5+.

Installing

composer require molovo/interrogate

Copy the included .env.example file from vendor/molovo/interrogate to your web server's DOCUMENT_ROOT, and rename it to .env. Then, update the new .env file with your database connection information.

Getting Started

Queries are built using chained methods, which try to follow SQL grammar as much as possible. Queries return a Collection object containing multiple Model objects.

use Molovo\Interrogate\Database;
use Molovo\Interrogate\Query;

Database::bootstrap();

$query = Query::table('users')
    ->select('username', 'email')
    ->where('name', 'Joe Bloggs');

// @var $users Molovo\Interrogate\Collection
$users = $query->fetch();

// @var $user Molovo\Interrogate\Model
foreach ($users as $user) {
    echo $user->username;
    echo $user->email;
}

Using Joins

Queries with joins can be built by passing another Query object to the join() method. The models returned by the joined query are stored in a property on the model, using the table name (or alias if defined). The joined query can compare fields on the parent query with dot syntax, using either the table name (or alias) directly, or the keyword parent as below.

use Molovo\Interrogate\Query;

$query = Query::table('users_table', 'users')
    ->select('name')
    ->join(Query::table('addresses_table', 'addresses')
        ->select('town')
        ->on('user_id', 'parent.id'));

$users = $query->fetch();

foreach ($users as $user) {
    // @var $addresses Molovo\Interrogate\Collection
    $addresses = $user->addresses;

    foreach ($addresses as $address) {
        echo $address->town;
    }
}

Using Models

Model classes can created for tables to allow for quick query creation, and adding functionality on a per-table basis. The simplest form of a model is shown below:

namespace Models;

use Molovo\Interrogate\Model;

class User extends Model {}

By default, the table name is the pluralized snake_cased equivalent of the class name. E.g. the model UserDetail refers to a table user_details. To use a different table name, define the static property $tableName.

class User extends Model {
    protected static $tableName = 'the_users_table';
}

Models make use of magic methods to allow static access to methods in the Query class.

$user = User::where('name', 'Joe Bloggs');

// is equivalent to

$user = Query::table('users')->where('name', 'Joe Bloggs');

You can also statically call methods on the Collection class.

$names = User::toList('name');

// is equivalent to

$collection = Query::table('users')->fetch();
$names = $collection->toList('name');

molovo/interrogate 适用场景与选型建议

molovo/interrogate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 109 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 01 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 molovo/interrogate 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2016-01-10