2017 © Pedro Peláez
 

library potato-orm

This package aims at building a simple agnostic ORM that can perform the basic crud database operations.

image

laztopaz/potato-orm

This package aims at building a simple agnostic ORM that can perform the basic crud database operations.

  • Sunday, April 3, 2016
  • by andela-tolotin
  • Repository
  • 1 Watchers
  • 5 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Potato ORM

Coverage Status Scrutinizer Code Quality Build Status, (*1)

Potato-ORM is a simple agnostic ORM (Object Relational Mapping) package that can perform basic CRUD (Create, Read, Update and Delete) operations., (*2)

How to use this package

Composer installation is required before using this package. To install a composer, try running this command on your terminal., (*3)

$ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin

Installation

PHP 5.5+ and Composer are required., (*4)

Via composer, (*5)

$ 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:, (*6)

<?php

use Laztopaz\potatoORM;

class User extends BaseModel {

}

You also need set your environment variables to define your database parameters., (*7)

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., (*8)

Support for database drivers

This package supports the following drivers;, (*9)

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., (*10)

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

<?php, (*11)

$users = User::getAll();

print_r($users);

Update an existing record

<?php

$user         = User::find(1);
$user->name   = "Olotin Temitope";
$user->stack  = "Java/Android";
$user->alias  = "Laztopaz";
$user->save();

Delete a record

<?php 

User::destroy(1);

To make this package degrade gracefully, you will need to wrap it around try and catch so that all exceptions are caught. For instance, to catch exception on save new record try this., (*12)

 <?php

    try {
        $user         = new User();
        $user->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, (*13)

 <?php
     try {
         $users = User::getAll();
         print_r($users);

     } catch (Exception $e) {
         echo $e->getMessage();
     }

Also for find and update method, you can also wrap it around try and catch., (*14)

<?php

  try {
      $user         = User::find(1);
      $user->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., (*15)

<?php

  try {
      User::destroy(1);
  } catch (Exception $e) {
       echo $e->getMessage();
  }

Testing

Run this command on your terminal, (*16)

$ composer test or phpunit test

Contributing

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

Credit

Potato ORM Package is created and maintained by Temitope Olotin., (*18)

The Versions

03/04 2016

dev-test

dev-test

This package aims at building a simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Temitope Olotin

03/03 2016

dev-analysis-zRvMAO

dev-analysis-zRvMAO

This package aims at building a simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Temitope Olotin

01/03 2016

dev-database

dev-database

This package aims at building a simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Temitope Olotin