PHP Classes
elePHPant
Icontem

Potato ORM: Store and retrieve objects in databases using ORM

Recommend this page to a friend!
  Info   View files Documentation   View files View files (29)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2015-12-18 (10 months ago) RSS 2.0 feedNot enough user ratingsTotal: 114 This week: 1All time: 8,401 This week: 1,047Up
Version License PHP version Categories
potato-orm 1.0.0BSD License5PHP 5, Databases, Design Patterns
Description Author

This package can store and retrieve objects in databases using ORM.

It provides a base model class that can be extended by applications to create entity classes that can perform different operations to store and retrieve objects from a database table.

Currently it can get all records of a table, get one object by id or that has a given value in a field, save an object to the database table, delete one object.

This package can also create database tables with support to foreign keys.

The database is access using PDO. It supports MySQL, PostgreSQL and SQLite.

Picture of adeniyi ibraheem
  Performance   Level  

Details

Potato-ORM

Build Status License Quality Score Scruitinizer Code Code Climate Test Coverage

Potato-ORM is a package that manages the CRUD operation of database. Potato-ORM currently supports MYSQL, POSTGRES and SQLITE Database.

Installation

PHP 5.5+ and Composer are required.

Via Composer

$ composer require ibonly/potato-orm

$ composer install

Usage

App Namespace

    namespace Ibonly\PotatoORM

Create a Class that correspond to the singular form of the table name in the database. i.e.

<?php
    namespace Ibonly\PotatoORM;

    class User extends Model
    {

    }
?>

The Model class contains getAll(), where($field, $value), find($value), save() and detroy($id) methods.

getAll()

<?php
    use Ibonly\PotatoORM\User;

    $sugar = new User();
    echo $sugar->getAll();
?>

Return type = JSON

where($field, $value)

<?php
    use Ibonly\PotatoORM\User;

    $sugar = new User();
    echo $sugar->where($field, $value);
?>

Return type = JSON

find($value)

<?php
    use Ibonly\PotatoORM\User;

    $insert = User::find(1);
    $insert->password = "password";
    echo $insert->save()
?>

To return custom message, wrap the `save()` method in an `if statement`

Return type = Boolean

save()

<?php
    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

detroy($value)

<?php
    use Ibonly\PotatoORM\User;

    $insert = User::destroy(2);
    die($insert);
?>

Return type = Boolean

Create Database Table

Its is also possible to create Database Table with the Schema class. The table name will be specified in the createTable($name) method.

<?php
    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

Database Constraint

Foreign Key

```
    $user->field('foreignKey', 'id', 'users_id');
```

The reference table `(users)` and field `(id)` will be written as `(users_id)`

Unique

```
    $user->field('unique', 'email')
```

Testing

$ vendor/bin/phpunit test

Contributing

To contribute and extend the scope of this package, Please check out CONTRIBUTING file for detailed contribution guidelines.

Credits

Potato-ORM is created and maintained by Ibraheem ADENIYI.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file, 4 directories)
Files folder imagetest (3 files, 1 directory)
Accessible without login Plain text file .env.example Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file LICENCE Lic. License
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:114
This week:1
All time:8,401
This week:1,047Up