laztopaz/potato-orm
Composer 安装命令:
composer require laztopaz/potato-orm
包简介
This package aims at building a simple agnostic ORM that can perform the basic crud database operations.
README 文档
README
Potato-ORM is a simple agnostic ORM (Object Relational Mapping) package that can perform basic CRUD (Create, Read, Update and Delete) operations.
How to use this package
Composer installation is required before using this package. To install a composer, try running this command on your terminal.
$ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin
Installation
PHP 5.5+ and Composer are required.
Via composer
$ composer require laztopaz/potato-orm
Install
$ composer install
After you have installed the package via composer, then you are set to go. Next line of action is to create a class that extends a base Model class under the nameapace Laztopaz/potatoORM. For instance, a class for users or Users table should look like this:
<?php
use Laztopaz\potatoORM;
class User extends BaseModel {
}
You also need set your environment variables to define your database parameters.
databaseName = xxxxxxx
databaseDriver = mysql
databaseUsername = xxxxxxx
databasePassword = xxxxxxx
databasePort = 33060
databaseHost = 127.0.0.1:33060
The default database driver used for this package is mysql. If you wish to change to a new database, define the database parameters in the environment variable file.
Support for database drivers
This package supports the following drivers;
1. MySQL
2. Postgres
3. SQLite
To save a new record, you will need to instatiate the class that extends the base model class. Assume your model class is User.
Save a new record
<?php
$user = new User();
$user->name = "Temitope Olotin";
$user->gender = "Male";
$user->alias = "Laztopaz";
$user->class = "14";
$user->stack = "php/laravel";
$user->save();
Read all records from the users table
name = "Olotin Temitope"; $user->stack = "Java/Android"; $user->alias = "Laztopaz"; $user->save(); Delete a record ================== name = "Temitope Olotin"; $user->gender = "Male"; $user->alias = "Laztopaz"; $user->class = "14"; $user->stack = "php/laravel"; $user->save(); } catch (Exception $e) { echo $e->getMessage(); } Read all records from the users table getMessage(); } Also for find and update method, you can also wrap it around try and catch. name = "Olotin Temitope"; $user->stack = "Java/Android"; $user->alias = "Laztopaz"; $user->save(); } catch (Exception $e) { echo $e->getMessage(); } For deleting a record too, It is expected that you wrapped your code around try and catch also. getMessage(); } Testing ====== Run this command on your terminal $ composer test or phpunit test Contributing ========== To contribute and extend the scope of this package, Please check out [CONTRIBUTING file](https://github.com/andela-tolotin/Potato-ORM/blob/test/contribution.md) for detailed contribution guidelines. Credit ===== Potato ORM Package is created and maintained by Temitope Olotin.统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-29