dynamonet/orm 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

dynamonet/orm

Composer 安装命令:

composer require dynamonet/orm

包简介

Fluent Query Builder and ActiveRecord-based ORM for PHP 7

README 文档

README

ActiveRecord-based ORM for PHP 7, inspired in Eloquent and Yii2 ORM.

Getting Started

Create a new PDO instance, and pass the instance to Query:

use Dynamo\ORM\Query;
....
$pdo = new \PDO('mysql:dbname=goldoni;host=localhost;charset=utf8', 'root', 'root');
$query = (new Query($pdo))

or better yet, set the PDO globally:

Query::setPdo($pdo);
....
$query = (new Query()) // this will use the static PDO instance.

Query Builder

Fluent and intuitive Query Builder:

$users = (new Query)
  ->select('*') // This is the default select
  ->from('users')
  ->where([
    'role' => 'ADMIN', // translates to "role = ?", where "?" will be securely replaced by the PDO layer
    'age > $minAge', // insecure! $minAge is not verified! However, we allow this form for convenience
    [ 'age', '<=', $maxAge ], // better
  ], false) // false "OR's" all the previous conditions. Default is true, which will "AND" all the conditions. 
  ->all(); // Fetches all the results

Installing

composer require dynamonet/orm

Defining Models

Your database models classes should extend the Dynamo\ORM\ActiveModel class:

<?php

namespace MyApp;

use Dynamo\ORM\ActiveModel;

class User extends ActiveModel
{
    //
}

By convention, the "snake case" name of the class will be used as the table name. If you want to specify a different table name, you can do so by simply overriding the static "getTableName" method:

<?php

namespace MyApp;

use Dynamo\ORM\ActiveModel;

class User extends ActiveModel
{
    public static function getTableName()
    {
        return 'my_users_table';
    }
}

Relationships

Defining relationships is done quite the same way you would in Yii2's ORM or Eloquent.

one-to-one relationships

(work in progress)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固