Giter Site home page Giter Site logo

1651003674 / phero Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chenyingqiao/phero

0.0 1.0 0.0 351 KB

这个是一个独立的orm组件可以使用在任何系统中,提供灵活的orm操作,注解形式的数据库和类的映射。This is a database query tool library. swoole mysql pool.

PHP 100.00%

phero's Introduction

介绍

phero是一个数据库查询的orm类库,注解形式的model以及方便快速的数据库操作方法

这是一个兴趣使然的ORM(手动斜眼笑)

V1.0.3

支持下列特性:

文档位于doc 可以查看test中单元测试的例子

安装

  • composer
composer require lerko/p-hero
  • git clone
git clone https://github.com/chenyingqiao/Phero.git;

第一个ORM

创建一个Unit

<?php 
/**
 * @Table[name=Parent,alias=parent]  
 * # name表示真正的表名称,如果没有配置就是类名为表明
 * # alias为别名
 */
class Parents extends DbUnit
{
    use Truncate;
    /**
     * @Field[type=int] # 只有标示@Field的属性才会被作为查询列
     * @Primary #标示为主键
     * @var [type]
     */
    public $id;
    /**
     * @Field
     * @var [type]
     */
    public $name;
}

对应的表结构为

+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(45) | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+

进行一些基础的查询

单表

$parent=new Parent("name");# 你也可以这样获取Unit的实例  $parent=Parent::Inc();
$parent->whereEq("id",2)->select(Cache::time(10));//Cache::time(10)表示缓存10秒

select `mother`.`name` from `Mother` as `mother`;

子查询

$Parents=new Parents();
$Marry=new Marry();
//#是会自动替换成使用本实体为子查询的父实体
//或者使用Marry::FF("{字段名称}");也可以生成对应Unit的字段名String
$Marry->whereEq("pid","#.`id`");
$Parents->whereEq("id",1)
    ->whereOrExists($Marry)->select();
SELECT
    `parent`.`id`, `parent`.`name`
FROM
    `Parent` AS `parent`
WHERE
    `parent`.`id` = 1
        OR EXISTS(
            SELECT
                `Marry`.`id`, `Marry`.`pid`, `Marry`.`mid`
            FROM
                `Marry`
            WHERE
                `Marry`.`pid` = `parent`.`id`
        );
关键字 对应sql符号
where{and/or}Eq =
where{and/or}Neq <> (!=)
where{and/or}In in
where{and/or}Not_in not in
where{and/or}Between between
where{and/or}Like like
where{and/or}Not_like not like
where{and/or}Lt <
where{and/or}Lr <=
where{and/or}Gt >
where{and/or}Ge >=
where{and/or}Regexp regexp
where{and/or}Isnotnull is not null
where{and/or}Isnull is null
where{and/or}Exists exists
where{and/or}Not_exists not exists
where{Lt/Lr/Gt/Ge}{and/or}All all
where{Lt/Lr/Gt/Ge}{and/or}Any any

删除

$parent=new Parent();
$parent->whereEq("id",2)->delete();

更新

$parent=new Parent([
    "name"=>"this is change!"
]);
$parent->whereEq("id",2)->update();

插入

#id是自增主键没有进行赋值
$parent=new Parent([
    "name"=>"插入"
]);
#不用构造函数赋值你也可以这样直接赋值
$parent->name="这个是直接赋值";
$parent->insert();

phero's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.