2017 © Pedro Peláez
 

library potato-orm

A package that perform basic CRUD (create, read, update and delete) operations in your Database.

image

demola/potato-orm

A package that perform basic CRUD (create, read, update and delete) operations in your Database.

  • Monday, July 23, 2018
  • by andela-araimi
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Potato ORM

Coverage Status Build Status Scrutinizer Code Quality

Potato-ORM is based on concepts borrowed from the Laravel framework. It is a package that can perform the basic CRUD (create, read, update and delete) operations., (*1)

Installation

To install this package, PHP 5.5+ and Composer are required, (*2)

$ composer require demola/potato-orm, (*3)


Usage


To use this package, what you need to do is to simply extend the base class. The base class is an abstract class called "DataBaseModel". Take for instance, you wish to perform the CRUD operations on the users table. Create a corresponding users class which should look like this:, (*4)

use Demo;

class User extends DataBaseModel
{
}
  • Saving a new record to the table, (*5)

     $user               = new User();
     $user->name         = "Prosper Otemuyiwa";
     $user->sex          = "m";   
     $user->occupation   = "Trainer";
     $user->organisation = "Andela";
     $user->year         = 2009;
     $user->save();  
  • Read all record from the table, (*6)

     $users = User::getAll();
     print_r($users);
  • Read from a particular record in the table, (*7)

    $user = User::findById(3);
    print_r($user->getById());
  • Update a record in the table. For example, update the name of the tenth record in the users table:, (*8)

    $user       = User::findById(10);
    $user->name = "Gbolohan Kuti";
    $user->save();
  • Delete a record in the table. For example, delete the eighth record in the users table:, (*9)

    $users = User::destroy(8);
  • Exception Handling, (*10)

To make this package degrade gracefully, It has to be wrapped under try and catch in order for all exceptions to be caught., (*11)

  • Catching exception on save new record:, (*12)

     try {
         $user               = new User();
         $user->name         = "Prosper Otemuyiwa";
         $user->sex          = "m";   
         $user->occupation   = "Trainer";
         $user->organisation = "Andela";
         $user->year         = 2009;
         $user->save(); 
         } catch(Exception $e) {
             print($e->getMessage());
         } 
  • Catching exception on reading from the table:, (*13)

        /**
         * Read all record
         * / 
        try {
            $users = User::getAll();
            print_r($users);
        } catch(Exception $e) {
            print($e->getMessage());
        } 
    
        /**
         * Read from a particular record
         * / 
        try {
            $user = User::findById(3);
            print_r($user->getById());
        } catch(Exception $e) {
            print($e->getMessage());
        } 
  • Catching exception on updating the table:, (*14)

        try {
            $user       = User::findById(10);
            $user->name = "Gbolohan Kuti";
            $user->save();
         } catch(Exception $e) {
            print($e->getMessage());
         } 
  • Catching exception on deleting from the table:, (*15)

         try {
             $users = User::destroy(8);
         } catch(Exception $e) {
             print($e->getMessage());
         } 

Testing


Run the following command in the potato-orm directory:, (*16)

~ phpunit tests

Change log


Please check out CHANGELOG file for information on what has changed recently., (*17)

Contributing


Please check out CONTRIBUTING file for detailed contribution guidelines., (*18)

Security


If you discover any issue, kindly contact ademola.raimi@andela.com, (*19)

Credits


Potato-ORM is maintained by Raimi Ademola., (*20)

License


Potato-ORM is released under the MIT Licence. See the bundled LICENSE file for more details., (*21)

The Versions

23/07 2018

dev-master

9999999-dev https://github.com/andela-araimi/potato-orm.git

A package that perform basic CRUD (create, read, update and delete) operations in your Database.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Raimi Ademola

orm