emeka/candy

V1.0.0 2015-11-10 18:59 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:42:21 UTC


README

Build Status Scrutinizer Code Quality

Candy是一个使用PHP编写的轻量级ORM

##测试使用phpunit框架进行单元测试,以对类进行单元测试。应用了TDD原则以使应用程序更加健壮

在bash中运行以下命令以执行测试

 /vendor/bin/phpunit

##安装

  • 要安装此包,需要PHP 5.5+和Composer
composer require emeka/candy

##基本的CRUD操作所有查询都需要一个Mapper实例。Mapper负责查找和更新或删除单个实体。

##使用Candy进行查询

##all()

  • 从数据库的字段中查找并返回所有实体。
$users = User::all();
echo $users;

##find($id)

  • 从数据库中查找并返回单个实体。
$users = User::find($id);
echo $users;

##where($value, $field) 查找所有匹配给定条件的实体并从数据库中返回记录。

$value = "username"
$field = "user's table"

echo $user = User::where($value, $field)

##Save

  • save方法是一个便利方法,它处理实体对象的插入和更新。根据实体是否有ID属性来决定调用insert还是update。

####Insert

$user = new User;
$user->email     = "john@doe.co";
$user->username  = "john";
$user->password  = "password";
//without the ID property the Save method will insert a new record in to  the database 
$user::save();

####Update

$user = new User;
$user->id        = 1;
$user->email     = "new_john@doe.co";
$user->username  = "new_john";
$user->password  = "new_password";
//with the ID property the Save method will update the USERS table where ID = 1. 
$user::save();

##Delete

  • 从数据库中删除。
$user = User::destroy($id):
$user returns a boolean

变更日志

请查看CHANGELOG文件以获取最近更改的信息。

贡献

请查看CONTRIBUTING文件以获取详细的贡献指南。

鸣谢

Candy由Emeka Osuagwu维护。

许可证

Urban dictionary在MIT许可证下发布。有关更多详细信息,请参阅附带LICENSE文件。