ibonly / potato-orm
此包的最新版本(1.1)没有可用的许可信息。
1.1
2016-05-03 12:37 UTC
Requires
- php: >=5.5
- vlucas/phpdotenv: ^2.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- mockery/mockery: >=0.7.2
- phpunit/phpunit: 4.8.*
This package is not auto-updated.
Last update: 2024-09-14 17:48:20 UTC
README
ƒ# Potato-ORM
Potato-ORM 是一个用于管理数据库 CRUD 操作的包。Potato-ORM 目前支持 MYSQL
、POSTGRES
和 SQLITE
数据库。
安装
需要 PHP 5.5+ 和 Composer。
通过 Composer
$ composer require ibonly/potato-orm
$ composer install
用法
应用命名空间
namespace Ibonly\PotatoORM
创建一个与数据库中表名单数形式相对应的 Class
。例如:
namespace Ibonly\PotatoORM; class User extends Model { protected $table = 'tableName'; protected fillables = ['name', 'email']; }
如果用户想指定表名,也可以在模型中定义。
要输出的字段也可以指定为 protected $fillables = []
。
模型类包含 getAll()
、where([$field => $value])
、find($value)
、save()
、update()
和 destroy($id)
方法。
getAll()
use Ibonly\PotatoORM\User; $sugar = new User(); return $sugar->getAll()->all();
Return type = JSON
where($field, $value)
use Ibonly\PotatoORM\User; $sugar = new User(); return $sugar->where([$field => $value])->first()->username;
向 where 传递条件
return $sugar->where([$field => $value, $field2 => $value2], 'AND')->first()->username;
Return type = String
Update($value)
use Ibonly\PotatoORM\User; $update = new User(); $update->password = "password"; echo $insert->update(1)
To return custom message, wrap the `save()` method in an `if statement`
Return type = Boolean
save()
use Ibonly\PotatoORM\User; $insert = new User(); $insert->id = NULL; $insert->username = "username"; $insert->email = "example@example.com"; $insert->password = "password"; echo $insert->save();
To return custom message, wrap the `save()` method in an `if statement`
Return type = Boolean
file($fileName)->uploadFile()
此方法用于上传文件,它只能与 save()
和 update($id)
一起使用。
use Ibonly\PotatoORM\User; $insert = new User(); $insert->id = NULL; $insert->username = "username"; $insert->email = "example@example.com"; $insert->avatar = $this->content->file($_FILES['image'])->uploadFile($uploadDirectory); $insert->password = "password"; echo $insert->save();
detroy($value)
use Ibonly\PotatoORM\User; $insert = User::destroy(2); die($insert);
Return type = Boolean
创建数据库表
也可以使用 Schema
类创建数据库表。表名将在 createTable($name)
方法中指定。
use Ibonly\PotatoORM\Schema; $user = new Schema; $user->field('increments', 'id'); $user->field('strings', 'username'); $user->field('strings', 'name', 50); $user->field('integer', 'age'); $user->field('primaryKey', 'id'); echo $table->createTable('players');
Return type = Boolean
数据库约束
外键
$user->field('foreignKey', 'id', 'users-id');
参照表 (users)
和字段 (id)
将写作 (users-id)
唯一键
$user->field('unique', 'email')
测试
$ vendor/bin/phpunit test
贡献
要贡献并扩展此包的范围,请查看 CONTRIBUTING 文件以获取详细的贡献指南。
鸣谢
Potato-ORM 由 Ibraheem ADENIYI
创建和维护。