2017 © Pedro Peláez
 

library potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

image

john-kariuki/potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  • Saturday, April 16, 2016
  • by andela-jkariuki
  • Repository
  • 1 Watchers
  • 1 Stars
  • 131 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 16 Versions
  • 0 % Grown

The README.md

Checkpoint Two: Potato ORM

Build Status Scrutinizer Code Quality Coverage Status Latest Version on Packagist ![Total Downloads][ico-downloads] Software License, (*1)

Andela Checkpoint Two

A simple agnostic ORM that can perform the basic crud database operations., (*2)

TIA

Install

Via Composer, (*3)

$ composer require john-kariuki/potato-orm

Via Github, (*4)

``` bash $ git clone git@github.com:andela-jkariuki/checkpoint-two-potato-orm.git, (*5)


Update packages ``` bash $ composer install

Rename .env.example to .env, (*6)

Update your .env to have your database credentials, (*7)

DB_DRIVER = "sqlite"
DB_USERNAME = "homestead"
DB_PASSWORD = "secret"
DB_NAME = "potato.db"
DB_HOST = "localhost"
DB_PORT = 8000

Usage

To use Potato ORM, extend the PotatoModel class., (*8)

The default naming convention for a table name associated with a class is it's lowercase plural syntax., (*9)

The default naming convention for the unique table field is id., (*10)

To overwrite the default naming conventions, declare protected variables as explained below., (*11)

/**
 * Default table name for Car class is cars.
 *
 * Default uniqueId field for table cars is id
 */
class Car extends PotatoModel
{
    //protected static $table = "your_table_name";
    //protected static $uniqueId = "your_unique_id";
}

Ensure the table exists before using the Potato ORM class to avoid exceptions., (*12)

Use the SQL statement template below, (*13)

CREATE TABLE `cars` (
    `id`    INTEGER PRIMARY KEY AUTOINCREMENT,
    `name`  TEXT,
    `model` TEXT,
    `year`  INTEGER
)

Potato ORM gives you access to the following methods;, (*14)

Reading Data, (*15)

//Get all rows that from a table
$cars = Car::getAll();

Inserting data, (*16)

//insert a new row to the table
$car = new Car();
$car->name = "Boss";
$car->model = "Up";
$car->year = 2013;

$car->save(); //returns a boolean value. true or false if saved or not respectively.

Updating data, (*17)

//Update an existing row in the database
$car = Car::find(1);
$car->name = "Me Hennesy";
$car->year = 2015;

Deleting data, (*18)

//delete an existing row in the table
var_dump(Car::destroy(1));

Sample Code

Ensure to write your code inside a try catch block to catch any exceptions, (*19)

namespace DryRun;

use Potato\Manager\PotatoModel;
use PDOException;

require 'vendor/autoload.php';

class Car extends PotatoModel
{
    //protected static $table = "your_table_name";
    //protected static $uniqueId = "your_unique_id";
}
try {

    echo "Create a new Car\n";

    $car = new Car();
    $car->name = "Lambo";
    $car->model = "Hura";
    $car->year = 2013;

    if ( $car->save()) {
       echo "\nCar has been created.\n\n";
    } else {
       echo "There was an error saving your car.";
    }

    echo  "Find the car that has just been created and updated the name and year\n";

    $car = Car::find(1);

    $car->name = "Huracan";
    $car->year = 2015;


    echo $car->save();

    echo "\None row (of our new Car) has been updated.\n\n";

    echo "Get all cars and print them out\n\n";
    $cars = Car::getAll();
    print_r($cars);

    echo "\nAwesome.! Now let's delete the old car. Buy A new one if you can\n\n";

    var_dump(Car::destroy(1));
    print_r(Car::getAll());

    echo "\nYour old car is dead and gone\n";

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

Contributing

Contributions are welcome and will be fully credited., (*20)

We accept contributions via Pull Requests on Github., (*21)

Pull Requests

  • PSR-2 Coding Standard - The easiest way to apply the conventions is to install PHP Code Sniffer., (*22)

  • Add tests! - Your patch won't be accepted if it doesn't have tests., (*23)

  • Document any change in behaviour - Make sure the README.md and any other relevant documentation are kept up-to-date., (*24)

  • Consider our release cycle - We try to follow SemVer v2.0.0. Randomly breaking public APIs is not an option., (*25)

  • Create feature branches - Don't ask us to pull from your master branch., (*26)

  • One pull request per feature - If you want to do more than one thing, send multiple pull requests., (*27)

  • Send coherent history - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting., (*28)

Security

If you discover any security related issues, please email me at John Kariuki or create an issue., (*29)

Credits

John kariuki, (*30)

License

The MIT License (MIT)

Copyright (c) 2016 John kariuki john.kariuki@andela.com, (*31)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*32)

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*33)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*34)

The Versions

16/04 2016

dev-master

9999999-dev https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

16/04 2016

dev-develop

dev-develop https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

27/02 2016

1.1.3

1.1.3.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

27/02 2016

1.1.1

1.1.1.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

27/02 2016

1.1.2

1.1.2.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

26/02 2016

1.1.0

1.1.0.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

26/02 2016

1.0.9

1.0.9.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

26/02 2016

1.0.8

1.0.8.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

26/02 2016

1.0.7

1.0.7.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

25/02 2016

1.0.6

1.0.6.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

25/02 2016

1.0.5

1.0.5.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

25/02 2016

1.0.4

1.0.4.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

24/02 2016

1.0.3

1.0.3.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

18/02 2016

1.0.2

1.0.2.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

17/02 2016

1.0.1

1.0.1.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki

13/02 2016

1.0.0

1.0.0.0 https://github.com/andela-jkariuki/checkpoint-two-potato-orm

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

  Sources   Download

MIT

The Requires

 

by :John Kariuki

potato-orm john-kariuki